code:
/*
 * Song.h - class song - the root of the model-tree
 *
 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef SONG_H
#define SONG_H

#include <utility>

#include <QtCore/QSharedMemory>
#include <QtCore/QVector>
#include <QHash>
#include <QString>

#include "TrackContainer.h"
#include "Controller.h"
#include "MeterModel.h"
#include "Mixer.h"
#include "VstSyncController.h"

class AutomationTrack;
class Pattern;
class TimeLineWidget;

const bpm_t MinTempo = 10;
const bpm_t DefaultTempo = 140;
const bpm_t MaxTempo = 999;
const tick_t MaxSongLength = 9999 * DefaultTicksPerBar;

class LMMS_EXPORT Song : public TrackContainer
{
	Q_OBJECT
	mapPropertyFromModel( int,getTempo,setTempo,m_tempoModel );
	mapPropertyFromModel( int,masterPitch,setMasterPitch,m_masterPitchModel );
	mapPropertyFromModel( int,masterVolume,setMasterVolume, m_masterVolumeModel );
public:
	enum PlayModes
	{
		Mode_None,
		Mode_PlaySong,
		Mode_PlayBB,
		Mode_PlayPattern,
		Mode_PlayAutomationPattern,
		Mode_Count
	} ;

	struct SaveOptions {
		/**
		 * Should we discard MIDI ControllerConnections from project files?
		 */
		BoolModel discardMIDIConnections{false};

		void setDefaultOptions() {
			discardMIDIConnections.setValue(false);
		}
	};

	void clearErrors();
	void collectError( const QString error );
	bool hasErrors();
	QString errorSummary();

	class PlayPos : public TimePos
	{
	public:
		PlayPos( const int abs = 0 ) :
			TimePos( abs ),
			m_timeLine( NULL ),
			m_currentFrame( 0.0f )
		{
		}
		inline void setCurrentFrame( const float f )
		{
			m_currentFrame = f;
		}
		inline float currentFrame() const
		{
			return m_currentFrame;
		}
		inline void setJumped( const bool jumped )
		{
			m_jumped = jumped;
		}
		inline bool jumped() const
		{
			return m_jumped;
		}
		TimeLineWidget * m_timeLine;

	private:
		float m_currentFrame;
		bool m_jumped;

	} ;

	void processNextBuffer();

	inline int getLoadingTrackCount() const
	{
		return m_nLoadingTrack;
	}

	inline int getMilliseconds() const
	{
		return m_elapsedMilliSeconds[m_playMode];
	}

	inline int getMilliseconds(PlayModes playMode) const
	{
		return m_elapsedMilliSeconds[playMode];
	}

	inline void setToTime(TimePos const & pos)
	{
		m_elapsedMilliSeconds[m_playMode] = pos.getTimeInMilliseconds(getTempo());
		m_playPos[m_playMode].setTicks(pos.getTicks());
	}

	inline void setToTime(TimePos const & pos, PlayModes playMode)
	{
		m_elapsedMilliSeconds[playMode] = pos.getTimeInMilliseconds(getTempo());
		m_playPos[playMode].setTicks(pos.getTicks());
	}

	inline void setToTimeByTicks(tick_t ticks)
	{
		m_elapsedMilliSeconds[m_playMode] = TimePos::ticksToMilliseconds(ticks, getTempo());
		m_playPos[m_playMode].setTicks(ticks);
	}

	inline void setToTimeByTicks(tick_t ticks, PlayModes playMode)
	{
		m_elapsedMilliSeconds[playMode] = TimePos::ticksToMilliseconds(ticks, getTempo());
		m_playPos[playMode].setTicks(ticks);
	}

	inline int getBars() const
	{
		return currentBar();
	}

	inline int ticksPerBar() const
	{
		return TimePos::ticksPerBar(m_timeSigModel);
	}

	// Returns the beat position inside the bar, 0-based
	inline int getBeat() const
	{
		return getPlayPos().getBeatWithinBar(m_timeSigModel);
	}
	// the remainder after bar and beat are removed
	inline int getBeatTicks() const
	{
		return getPlayPos().getTickWithinBeat(m_timeSigModel);
	}
	inline int getTicks() const
	{
		return currentTick();
	}
	inline f_cnt_t getFrames() const
	{
		return currentFrame();
	}
	inline bool isPaused() const
	{
		return m_paused;
	}

	inline bool isPlaying() const
	{
		return m_playing == true && m_exporting == false;
	}

	inline bool isStopped() const
	{
		return m_playing == false && m_paused == false;
	}

	inline bool isExporting() const
	{
		return m_exporting;
	}

	inline void setExportLoop( bool exportLoop )
	{
		m_exportLoop = exportLoop;
	}

	inline bool isRecording() const
	{
		return m_recording;
	}

	inline void setLoopRenderCount(int count)
	{
		if (count < 1)
			m_loopRenderCount = 1;
		else
			m_loopRenderCount = count;
		m_loopRenderRemaining = m_loopRenderCount;
	}

	inline int getLoopRenderCount() const
	{
		return m_loopRenderCount;
	}

	bool isExportDone() const;
	int getExportProgress() const;

	inline void setRenderBetweenMarkers( bool renderBetweenMarkers )
	{
		m_renderBetweenMarkers = renderBetweenMarkers;
	}

	inline PlayModes playMode() const
	{
		return m_playMode;
	}

	inline PlayPos & getPlayPos( PlayModes pm )
	{
		return m_playPos[pm];
	}
	inline const PlayPos & getPlayPos( PlayModes pm ) const
	{
		return m_playPos[pm];
	}
	inline PlayPos & getPlayPos()
	{
		return getPlayPos(m_playMode);
	}
	inline const PlayPos & getPlayPos() const
	{
		return getPlayPos(m_playMode);
	}

	void updateLength();
	bar_t length() const
	{
		return m_length;
	}

	bpm_t getTempo();
	AutomationPattern * tempoAutomationPattern() override;

	AutomationTrack * globalAutomationTrack()
	{
		return m_globalAutomationTrack;
	}

	//TODO: Add Q_DECL_OVERRIDE when Qt4 is dropped
	AutomatedValueMap automatedValuesAt(TimePos time, int tcoNum = -1) const override;

	// file management
	void createNewProject();
	void createNewProjectFromTemplate( const QString & templ );
	void loadProject( const QString & filename );
	bool guiSaveProject();
	bool guiSaveProjectAs( const QString & filename );
	bool saveProjectFile( const QString & filename );

	const QString & projectFileName() const
	{
		return m_fileName;
	}

	bool isLoadingProject() const
	{
		return m_loadingProject;
	}

	void loadingCancelled()
	{
		m_isCancelled = true;
		Engine::mixer()->clearNewPlayHandles();
	}

	bool isCancelled()
	{
		return m_isCancelled;
	}

	bool isModified() const
	{
		return m_modified;
	}

	QString nodeName() const override
	{
		return "song";
	}

	virtual bool fixedTCOs() const
	{
		return false;
	}

	void addController( Controller * c );
	void removeController( Controller * c );

	const ControllerVector & controllers() const
	{
		return m_controllers;
	}

	MeterModel & getTimeSigModel()
	{
		return m_timeSigModel;
	}

	void exportProjectMidi(QString const & exportFileName) const;

	inline void setLoadOnLaunch(bool value) { m_loadOnLaunch = value; }
	SaveOptions &getSaveOptions() {
		return m_saveOptions;
	}

	bool isSavingProject() const;

public slots:
	void playSong();
	void record();
	void playAndRecord();
	void playBB();
	void playPattern( const Pattern * patternToPlay, bool loop = true );
	void togglePause();
	void stop();

	void startExport();
	void stopExport();

	void setModified();

	void clearProject();

	void addBBTrack();

private slots:
	void insertBar();
	void removeBar();
	void addSampleTrack();
	void addAutomationTrack();

	void setTempo();
	void setTimeSignature();

	void masterVolumeChanged();

	void savePos();

	void updateFramesPerTick();

private:
	Song();
	Song( const Song & );
	virtual ~Song();

	inline bar_t currentBar() const
	{
		return m_playPos[m_playMode].getBar();
	}

	inline tick_t currentTick() const
	{
		return m_playPos[m_playMode].getTicks();
	}

	inline f_cnt_t currentFrame() const
	{
		return m_playPos[m_playMode].getTicks() * Engine::framesPerTick() +
			m_playPos[m_playMode].currentFrame();
	}

	void setPlayPos( tick_t ticks, PlayModes playMode );

	void saveControllerStates( QDomDocument & doc, QDomElement & element );
	void restoreControllerStates( const QDomElement & element );

	void removeAllControllers();

	void processAutomations(const TrackList& tracks, TimePos timeStart, fpp_t frames);

	void setModified(bool value);

	void setProjectFileName(QString const & projectFileName);

	AutomationTrack * m_globalAutomationTrack;

	IntModel m_tempoModel;
	MeterModel m_timeSigModel;
	int m_oldTicksPerBar;
	IntModel m_masterVolumeModel;
	IntModel m_masterPitchModel;

	ControllerVector m_controllers;

	int m_nLoadingTrack;

	QString m_fileName;
	QString m_oldFileName;
	bool m_modified;
	bool m_loadOnLaunch;

	volatile bool m_recording;
	volatile bool m_exporting;
	volatile bool m_exportLoop;
	volatile bool m_renderBetweenMarkers;
	volatile bool m_playing;
	volatile bool m_paused;

	bool m_savingProject;
	bool m_loadingProject;
	bool m_isCancelled;

	SaveOptions m_saveOptions;

	QHash<QString, int> m_errors;

	PlayModes m_playMode;
	PlayPos m_playPos[Mode_Count];
	bar_t m_length;

	const Pattern* m_patternToPlay;
	bool m_loopPattern;

	double m_elapsedMilliSeconds[Mode_Count];
	tick_t m_elapsedTicks;
	bar_t m_elapsedBars;

	VstSyncController m_vstSyncController;

	int m_loopRenderCount;
	int m_loopRenderRemaining;
	TimePos m_exportSongBegin;
	TimePos m_exportLoopBegin;
	TimePos m_exportLoopEnd;
	TimePos m_exportSongEnd;
	TimePos m_exportEffectiveLength;

	friend class LmmsCore;
	friend class SongEditor;
	friend class mainWindow;
	friend class ControllerRackView;

signals:
	void projectLoaded();
	void playbackStateChanged();
	void playbackPositionChanged();
	void lengthChanged( int bars );
	void tempoChanged( bpm_t newBPM );
	void timeSignatureChanged( int oldTicksPerBar, int ticksPerBar );
	void controllerAdded( Controller * );
	void controllerRemoved( Controller * );
	void updateSampleTracks();
	void stopped();
	void modified();
	void projectFileNameChanged();
} ;

#endif


code:
/*
 * SongEditor.h - declaration of class SongEditor, a window where you can
 *                 setup your songs
 *
 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef SONG_EDITOR_H
#define SONG_EDITOR_H

#include <QVector>
#include <QLinearGradient>

#include "ActionGroup.h"
#include "Editor.h"
#include "TrackContainerView.h"
#include "PositionLine.h"

class QLabel;
class QScrollBar;

class AutomatableSlider;
class ComboBox;
class ComboBoxModel;
class LcdSpinBox;
class MeterDialog;
class Song;
class TextFloat;
class TimeLineWidget;

class SongEditor : public TrackContainerView
{
	Q_OBJECT
public:
	enum EditMode
	{
		DrawMode,
		SelectMode
	};

	SongEditor( Song * song );
	~SongEditor();

	void saveSettings( QDomDocument& doc, QDomElement& element ) override;
	void loadSettings( const QDomElement& element ) override;

	ComboBoxModel *zoomingModel() const;
	ComboBoxModel *snappingModel() const;
	float getSnapSize() const;
	QString getSnapSizeString() const;

public slots:
	void scrolled( int new_pos );
	void selectRegionFromPixels(int xStart, int xEnd);
	void stopSelectRegion();
	void updateRubberband();

	void setEditMode( EditMode mode );
	void setEditModeDraw();
	void setEditModeSelect();
	void toggleProportionalSnap();

	void updatePosition( const TimePos & t );
	void updatePositionLine();
	void selectAllTcos( bool select );

protected:
	void closeEvent( QCloseEvent * ce ) override;
	void mousePressEvent(QMouseEvent * me) override;
	void mouseMoveEvent(QMouseEvent * me) override;
	void mouseReleaseEvent(QMouseEvent * me) override;

private slots:
	void setHighQuality( bool );

	void setMasterVolume( int new_val );
	void showMasterVolumeFloat();
	void updateMasterVolumeFloat( int new_val );
	void hideMasterVolumeFloat();

	void setMasterPitch( int new_val );
	void showMasterPitchFloat();
	void updateMasterPitchFloat( int new_val );
	void hideMasterPitchFloat();

	void updateScrollBar(int len);

	void zoomingChanged();

private:
	void keyPressEvent( QKeyEvent * ke ) override;
	void wheelEvent( QWheelEvent * we ) override;

	bool allowRubberband() const override;

	int trackIndexFromSelectionPoint(int yPos);
	int indexOfTrackView(const TrackView* tv);

	Song * m_song;

	QScrollBar * m_leftRightScroll;

	LcdSpinBox * m_tempoSpinBox;

	TimeLineWidget * m_timeLine;

	MeterDialog * m_timeSigDisplay;
	AutomatableSlider * m_masterVolumeSlider;
	AutomatableSlider * m_masterPitchSlider;

	TextFloat * m_mvsStatus;
	TextFloat * m_mpsStatus;

	PositionLine * m_positionLine;

	ComboBoxModel* m_zoomingModel;
	ComboBoxModel* m_snappingModel;
	bool m_proportionalSnap;

	static const QVector<double> m_zoomLevels;

	bool m_scrollBack;
	bool m_smoothScroll;

	EditMode m_mode;
	EditMode m_ctrlMode; // mode they were in before they hit ctrl

	QPoint m_origin;
	QPoint m_scrollPos;
	QPoint m_mousePos;
	int m_rubberBandStartTrackview;
	TimePos m_rubberbandStartTimePos;
	int m_currentZoomingValue;
	int m_trackHeadWidth;
	bool m_selectRegion;

	friend class SongEditorWindow;

signals:
	void zoomingValueChanged( double );
} ;

class SongEditorWindow : public Editor
{
	Q_OBJECT
public:
	SongEditorWindow( Song* song );

	QSize sizeHint() const override;

	SongEditor* m_editor;

protected:
	void resizeEvent( QResizeEvent * event ) override;
	void changeEvent( QEvent * ) override;

protected slots:
	void play() override;
	void record() override;
	void recordAccompany() override;
	void stop() override;

	void lostFocus();
	void adjustUiAfterProjectLoad();

	void updateSnapLabel();

signals:
	void playTriggered();
	void resized();

private:
	void keyPressEvent( QKeyEvent * ke ) override;
	void keyReleaseEvent( QKeyEvent * ke ) override;

	QAction* m_addBBTrackAction;
	QAction* m_addSampleTrackAction;
	QAction* m_addAutomationTrackAction;
	QAction* m_setProportionalSnapAction;

	ActionGroup * m_editModeGroup;
	QAction* m_drawModeAction;
	QAction* m_selectModeAction;
	QAction* m_crtlAction;

	ComboBox * m_zoomingComboBox;
	ComboBox * m_snappingComboBox;
	QLabel* m_snapSizeLabel;

	QAction* m_insertBarAction;
	QAction* m_removeBarAction;
};

#endif

repo_name: CYBERDEViL/LMMS

license: mit


code:
/*
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef STEP_RECORDER_H
#define STEP_RECORDER_H

#include <QElapsedTimer>
#include <QTimer>
#include <QObject>
#include <QKeyEvent>

#include "Note.h"
#include "lmms_basics.h"
#include "Pattern.h"

class PianoRoll;
class StepRecorderWidget;

class StepRecorder : public QObject
{
	Q_OBJECT

	public:
	StepRecorder(PianoRoll& pianoRoll, StepRecorderWidget& stepRecorderWidget);

	void initialize();
	void start(const TimePos& currentPosition,const TimePos& stepLength);
	void stop();
	void notePressed(const Note & n);
	void noteReleased(const Note & n);
	bool keyPressEvent(QKeyEvent* ke);
	bool mousePressEvent(QMouseEvent* ke);
	void setCurrentPattern(Pattern* newPattern);
	void setStepsLength(const TimePos& newLength);

	QVector<Note*> getCurStepNotes();

	bool isRecording() const
	{
		return m_isRecording;
	}

	QColor curStepNoteColor() const
	{
		return QColor(245,3,139); // radiant pink
	}

	private slots:
	void removeNotesReleasedForTooLong();

	private:
	void stepForwards();
	void stepBackwards();

	void applyStep();
	void dismissStep();
	void prepareNewStep();

	TimePos getCurStepEndPos();

	void updateCurStepNotes();
	void updateWidget();

	bool allCurStepNotesReleased();

	PianoRoll& m_pianoRoll;
	StepRecorderWidget& m_stepRecorderWidget;

	bool m_isRecording = false;
	TimePos m_curStepStartPos = 0;
	TimePos m_curStepEndPos = 0;

	TimePos m_stepsLength;
	TimePos m_curStepLength; // current step length refers to the step currently recorded. it may defer from m_stepsLength
							  // since the user can make current step larger

	QTimer m_updateReleasedTimer;

	Pattern* m_pattern;

	class StepNote
	{
		public:
		StepNote(const Note & note) : m_note(note), m_pressed(true) {};

		void setPressed()
		{
			m_pressed = true;
		}

		void setReleased()
		{
			m_pressed = false;
			releasedTimer.start();
		}

		int timeSinceReleased()
		{
			return releasedTimer.elapsed();
		}

		bool isPressed() const
		{
			return m_pressed;
		}

		bool isReleased() const
		{
			return !m_pressed;
		}

		Note m_note;

		private:
		bool m_pressed;
		QElapsedTimer releasedTimer;
	} ;

	QVector<StepNote*> m_curStepNotes; // contains the current recorded step notes (i.e. while user still press the notes; before they are applied to the pattern)

	StepNote* findCurStepNote(const int key);

	bool m_isStepInProgress = false;
};

#endif //STEP_RECORDER_H


code:
/*
 * StepRecorderWidget.h - widget that provide gui markers for step recording
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of"the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */
#ifndef STEP_RECOREDER_WIDGET_H
#define STEP_RECOREDER_WIDGET_H

#include "lmms_basics.h"
#include "Note.h"

#include <QWidget>
#include <QColor>
#include <QPainter>

class StepRecorderWidget : public QWidget
{
	Q_OBJECT

public:
	StepRecorderWidget(
		QWidget * parent,
		const int ppb,
		const int marginTop,
		const int marginBottom,
		const int marginLeft,
		const int marginRight);

	//API used by PianoRoll
	void setPixelsPerBar(int ppb);
	void setCurrentPosition(TimePos currentPosition);
	void setMargins(const QMargins &qm);
	void setBottomMargin(const int marginBottom);
	QMargins margins();

	//API used by StepRecorder
	void setStepsLength(TimePos stepsLength);
	void setStartPosition(TimePos pos);
	void setEndPosition(TimePos pos);

	void showHint();

private:
	void paintEvent(QPaintEvent * pe) override;

	int xCoordOfTick(int tick);

	void drawVerLine(QPainter* painter, int x, const QColor& color, int top, int bottom);
	void drawVerLine(QPainter* painter, const TimePos& pos, const QColor& color, int top, int bottom);

	void updateBoundaries();

	TimePos m_stepsLength;
	TimePos m_curStepStartPos;
	TimePos m_curStepEndPos;

	int m_ppb; // pixels per bar
	TimePos m_currentPosition; // current position showed by on PianoRoll

	QColor m_colorLineStart;
	QColor m_colorLineEnd;

	// boundaries within piano roll window
	int m_top;
	int m_bottom;
	int m_left;
	int m_right;

	const int m_marginTop;
	int m_marginBottom; // not const since can change on resize of edit-note area
	const int m_marginLeft;
	const int m_marginRight;

signals:
	void positionChanged(const TimePos & t);
} ;

#endif //STEP_RECOREDER_WIDGET_H


code:
/*
 * StringPairDrag.h - class StringPairDrag which provides general support
 *                      for drag'n'drop of string-pairs
 *
 * Copyright (c) 2005-2007 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef STRING_PAIR_DRAG_H
#define STRING_PAIR_DRAG_H

#include <QDrag>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMimeData>

#include "lmms_export.h"

class QPixmap;

class LMMS_EXPORT StringPairDrag : public QDrag
{
public:
	StringPairDrag( const QString & _key, const QString & _value,
					const QPixmap & _icon, QWidget * _w );
	~StringPairDrag();

	static bool processDragEnterEvent( QDragEnterEvent * _dee,
						const QString & _allowed_keys );
	static QString decodeKey( QDropEvent * _de );
	static QString decodeValue( QDropEvent * _de );
} ;

#endif


code:
/*
 * SubWindow.h - Implementation of QMdiSubWindow that correctly tracks
 *   the geometry that windows should be restored to.
 *   Workaround for https://bugreports.qt.io/browse/QTBUG-256
 *
 * Copyright (c) 2015 Colin Wallace <wallace.colin.a@gmail.com>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */
#ifndef SUBWINDOW_H
#define SUBWINDOW_H

#include <QEvent>
#include <QGraphicsDropShadowEffect>
#include <QMdiSubWindow>
#include <QLabel>
#include <QPushButton>
#include <QString>

#include "lmms_export.h"

class QMoveEvent;
class QResizeEvent;
class QWidget;

/**
 * @brief The SubWindow class
 *
 *  Because of a bug in the QMdiSubWindow class to save the right position and size
 *  of a subwindow in a project and because of the inability
 *  for cusomizing the title bar appearance, lmms implements its own subwindow
 *  class.
 */
class LMMS_EXPORT SubWindow : public QMdiSubWindow
{
	Q_OBJECT
	Q_PROPERTY( QBrush activeColor READ activeColor WRITE setActiveColor )
	Q_PROPERTY( QColor textShadowColor READ textShadowColor WRITE setTextShadowColor )
	Q_PROPERTY( QColor borderColor READ borderColor WRITE setBorderColor )

public:
	SubWindow( QWidget *parent = NULL, Qt::WindowFlags windowFlags = QFlag(0) );
	// same as QWidet::normalGeometry, but works properly under X11 (see https://bugreports.qt.io/browse/QTBUG-256)
	QRect getTrueNormalGeometry() const;
	QBrush activeColor() const;
	QColor textShadowColor() const;
	QColor borderColor() const;
	void setActiveColor( const QBrush & b );
	void setTextShadowColor( const QColor &c );
	void setBorderColor( const QColor &c );

protected:
	// hook the QWidget move/resize events to update the tracked geometry
	void moveEvent( QMoveEvent * event ) override;
	void resizeEvent( QResizeEvent * event ) override;
	void paintEvent( QPaintEvent * pe ) override;
	void changeEvent( QEvent * event ) override;

signals:
	void focusLost();

private:
	const QSize m_buttonSize;
	const int m_titleBarHeight;
	QPushButton * m_closeBtn;
	QPushButton * m_maximizeBtn;
	QPushButton * m_restoreBtn;
	QBrush m_activeColor;
	QColor m_textShadowColor;
	QColor m_borderColor;
	QPoint m_position;
	QRect m_trackedNormalGeom;
	QLabel * m_windowTitle;
	QGraphicsDropShadowEffect * m_shadow;
	bool m_hasFocus;

	static void elideText( QLabel *label, QString text );
	void adjustTitleBar();

private slots:
	void focusChanged( QMdiSubWindow * subWindow );
};

#endif


code:
/*
 * SweepOscillator.h - sweeping oscillator
 *
 * Copyright (c) 2006-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef SWEEP_OSCILLATOR_H
#define SWEEP_OSCILLATOR_H

#include "Oscillator.h"
#include "DspEffectLibrary.h"

template<class FX = DspEffectLibrary::StereoBypass>
class SweepOscillator
{
public:
	SweepOscillator( const FX & _fx = FX() ) :
		m_phase( 0.0f ),
		m_FX( _fx )
	{
	}

	virtual ~SweepOscillator()
	{
	}

	void update( sampleFrame* buf, const fpp_t frames, const float freq1, const float freq2, const float sampleRate )
	{
		const float df = freq2 - freq1;
		for( fpp_t frame = 0; frame < frames; ++frame )
		{
			const sample_t s = Oscillator::sinSample( m_phase );
			buf[frame][0] = s;
			buf[frame][1] = s;
			m_FX.nextSample( buf[frame][0], buf[frame][1] );
			m_phase += ( freq1 + ( frame * df / frames ) ) / sampleRate;
		}
	}

private:
	float m_phase;
	FX m_FX;

//	inline sample_t getSample( const float _sample );
//	inline void recalcPhase();

} ;

#endif


code:
/*
 * TabBar.h - class tabBar
 *
 * Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TAB_BAR_H
#define TAB_BAR_H

#include <QtCore/QMap>
#include <QLayout>
#include <QWidget>

#include "lmms_export.h"

class TabButton;

class LMMS_EXPORT TabBar : public QWidget
{
	Q_OBJECT
public:
	TabBar( QWidget * _parent,
			QBoxLayout::Direction _dir = QBoxLayout::LeftToRight );
	virtual ~TabBar() = default;

	TabButton * addTab( QWidget * _w, const QString & _text,
					int _id, bool _add_stretch = false,
					bool _text_is_tooltip = false );
	void removeTab( int _id );

	inline void setExclusive( bool _on )
	{
		m_exclusive = _on;
	}

	int activeTab();

public slots:
	void setActiveTab( int _id );

protected:
	bool tabState( int _id );
	void setTabState( int _id, bool _checked );
	bool allHidden();

protected slots:
	void hideAll( int _exception = -1 );
	void tabClicked( int _id );

private:
	QMap<int, QPair<TabButton *, QWidget *> > m_tabs;
	QBoxLayout * m_layout;
	bool m_exclusive;

signals:
	void allWidgetsHidden();
	void widgetShown();

} ;

#endif


code:
/*
 * TabButton.h - declaration of class TabButton
 *
 * Copyright (c) 2005-2007 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TAB_BUTTON_H
#define TAB_BUTTON_H

#include <QPushButton>

class TabButton : public QPushButton
{
	Q_OBJECT
public:
	TabButton( const QString & _text, int _id, QWidget * _parent ) :
		QPushButton( _text, _parent ),
		m_id( _id )
	{
		setCheckable( true );
		connect( this, SIGNAL( clicked() ), this,
						SLOT( slotClicked() ) );
	}

	~TabButton()
	{
	}

signals:
	void clicked( int );

protected slots:
	void slotClicked()
	{
		emit clicked( m_id );
	}

private:
	int m_id;

} ;

#endif


code:
/*
 * TabWidget.h - LMMS-tabwidget
 *
 * Copyright (c) 2005-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TAB_WIDGET_H
#define TAB_WIDGET_H

#include <QWidget>
#include <QtCore/QMap>

const int TEXT_TAB_HEIGHT = 14;
const int GRAPHIC_TAB_HEIGHT = 17;

class TabWidget : public QWidget
{
	Q_OBJECT
public:
	//! @param resizable If true, the widget resizes to fit the size of all tabs
	//!   If false, all child widget will be cut down to the TabWidget's size
	TabWidget( const QString & _caption, QWidget * _parent,
				bool usePixmap = false, bool resizable = false );
	virtual ~TabWidget() = default;

	void addTab( QWidget * w, const QString & name, const char *pixmap = NULL, int idx = -1 );

	void setActiveTab( int idx );

	int findTabAtPos( const QPoint *pos );

	inline int activeTab() const
	{
		return( m_activeTab );
	}

	// Themeability
	Q_PROPERTY( QColor tabText READ tabText WRITE setTabText)
	Q_PROPERTY( QColor tabTitleText READ tabTitleText WRITE setTabTitleText)
	Q_PROPERTY( QColor tabSelected READ tabSelected WRITE setTabSelected)
	Q_PROPERTY( QColor tabBackground READ tabBackground WRITE setTabBackground)
	Q_PROPERTY( QColor tabBorder READ tabBorder WRITE setTabBorder)

	QColor tabText() const;
	void setTabText( const QColor & c );
	QColor tabTitleText() const;
	void setTabTitleText( const QColor & c );
	QColor tabSelected() const;
	void setTabSelected( const QColor & c );
	QColor tabBackground() const;
	void setTabBackground( const QColor & c );
	QColor tabBorder() const;
	void setTabBorder( const QColor & c );

protected:
	bool event( QEvent * event ) override;
	void mousePressEvent( QMouseEvent * _me ) override;
	void paintEvent( QPaintEvent * _pe ) override;
	void resizeEvent( QResizeEvent * _re ) override;
	void wheelEvent( QWheelEvent * _we ) override;
	QSize minimumSizeHint() const override;
	QSize sizeHint() const override;

private:
	struct widgetDesc
	{
		QWidget * w;         // ptr to widget
		const char * pixmap; // artwork for the widget
		QString name;        // name for widget
		int nwidth;          // width of name when painting (only valid for text tab)
	} ;
	typedef QMap<int, widgetDesc> widgetStack;

	widgetStack m_widgets;

	bool	m_resizable;
	int 	m_activeTab;
	QString m_caption;      // Tab caption, used as the tooltip text on icon tabs
	quint8 	m_tabbarHeight; // The height of the tab bar
	quint8 	m_tabheight;    // The height of the tabs
	bool	m_usePixmap;      // true if the tabs are to be displayed with icons. False for text tabs.

	QColor m_tabText;       // The color of the tabs' text.
	QColor m_tabTitleText;  // The color of the TabWidget's title text.
	QColor m_tabSelected;   // The highlighting color for the selected tab.
	QColor m_tabBackground; // The TabWidget's background color.
	QColor m_tabBorder;     // The TabWidget's borders color.
} ;

#endif


code:
#ifndef TEMPLATESMENU_H
#define TEMPLATESMENU_H

#include <QDir>
#include <QMenu>

class TemplatesMenu : public QMenu
{
	Q_OBJECT
public:
	TemplatesMenu(QWidget *parent = nullptr);
	virtual ~TemplatesMenu() = default;

private slots:
	static void createNewProjectFromTemplate(QAction * _action);
	void fillTemplatesMenu();
	void addTemplatesFromDir( const QDir& dir );

};

#endif // TEMPLATESMENU_H


code:
/*
 * TempoSyncKnob.h - adds bpm to ms conversion for knob class
 *
 * Copyright (c) 2005-2008 Danny McRae <khjklujn/at/yahoo.com>
 * Copyright (c) 2009-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TEMPO_SYNC_KNOB_H
#define TEMPO_SYNC_KNOB_H

#include <QPixmap>
#include <QtCore/QPointer>

#include "Knob.h"
#include "TempoSyncKnobModel.h"

class MeterDialog;

class LMMS_EXPORT TempoSyncKnob : public Knob
{
	Q_OBJECT
public:
	TempoSyncKnob( knobTypes knobNum, QWidget* parent = NULL, const QString& name = QString() );
	virtual ~TempoSyncKnob();

	const QString & syncDescription();
	void setSyncDescription( const QString & _new_description );

	const QPixmap & syncIcon();
	void setSyncIcon( const QPixmap & _new_pix );

	TempoSyncKnobModel * model()
	{
		return castModel<TempoSyncKnobModel>();
	}

	void modelChanged() override;

signals:
	void syncDescriptionChanged( const QString & _new_description );
	void syncIconChanged();

protected:
	void contextMenuEvent( QContextMenuEvent * _me ) override;

protected slots:
	void updateDescAndIcon();
	void showCustom();

private:
	QPixmap m_tempoSyncIcon;
	QString m_tempoSyncDescription;

	QPointer<MeterDialog> m_custom;

} ;

#endif


code:
/*
 * TempoSyncKnobModel.h - adds bpm to ms conversion for knob class
 *
 * Copyright (c) 2005-2008 Danny McRae <khjklujn/at/yahoo.com>
 * Copyright (c) 2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TEMPO_SYNC_KNOB_MODEL_H
#define TEMPO_SYNC_KNOB_MODEL_H

#include "MeterModel.h"

class QAction;

class LMMS_EXPORT TempoSyncKnobModel : public FloatModel
{
	Q_OBJECT
	MODEL_IS_VISITABLE
public:
	enum TempoSyncMode
	{
		SyncNone,
		SyncDoubleWholeNote,
		SyncWholeNote,
		SyncHalfNote,
		SyncQuarterNote,
		SyncEighthNote,
		SyncSixteenthNote,
		SyncThirtysecondNote,
		SyncCustom
	} ;

	TempoSyncKnobModel( const float _val, const float _min,
				const float _max, const float _step,
				const float _scale, Model * _parent,
				const QString & _display_name = QString() );
	~TempoSyncKnobModel() override;

	void saveSettings( QDomDocument & _doc, QDomElement & _this, const QString& name ) override;
	void loadSettings( const QDomElement & _this, const QString& name ) override;

	TempoSyncMode syncMode() const
	{
		return m_tempoSyncMode;
	}

	void setSyncMode( TempoSyncMode _new_mode );

	float scale() const
	{
		return m_scale;
	}

	void setScale( float _new_scale );

signals:
	void syncModeChanged( TempoSyncMode _new_mode );
	void scaleChanged( float _new_scale );

public slots:
	inline void disableSync()
	{
		setTempoSync( SyncNone );
	}
	void setTempoSync( int _note_type );
	void setTempoSync( QAction * _item );

protected slots:
	void calculateTempoSyncTime( bpm_t _bpm );
	void updateCustom();

private:
	TempoSyncMode m_tempoSyncMode;
	TempoSyncMode m_tempoLastSyncMode;
	float m_scale;

	MeterModel m_custom;

	friend class TempoSyncKnob;

} ;

#endif


code:
/*
 * TextFloat.h - class textFloat, a floating text-label
 *
 * Copyright (c) 2005-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TEXT_FLOAT_H
#define TEXT_FLOAT_H

#include <QWidget>
#include <QPixmap>

#include "lmms_export.h"

class LMMS_EXPORT TextFloat : public QWidget
{
	Q_OBJECT
public:
	TextFloat();
	virtual ~TextFloat()
	{
	}

	void setTitle( const QString & _title );
	void setText( const QString & _text );
	void setPixmap( const QPixmap & _pixmap );

	void setVisibilityTimeOut( int _msecs );

	static TextFloat * displayMessage( const QString & _msg,
						int _timeout = 2000,
						QWidget * _parent = NULL,
						int _add_y_margin = 0 );
	static TextFloat * displayMessage( const QString & _title,
						const QString & _msg,
						const QPixmap & _pixmap =
								QPixmap(),
						int _timeout = 2000,
						QWidget * _parent = NULL );

	void moveGlobal( QWidget * _w, const QPoint & _offset )
	{
		move( _w->mapToGlobal( QPoint( 0, 0 ) )+_offset );
	}

protected:
	void paintEvent( QPaintEvent * _me ) override;
	void mousePressEvent( QMouseEvent * _me ) override;

private:
	void updateSize();

	QString m_title;
	QString m_text;
	QPixmap m_pixmap;

};

#endif


code:
/*
 * ThreadableJob.h - declaration of class ThreadableJob
 *
 * Copyright (c) 2009-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef THREADABLE_JOB_H
#define THREADABLE_JOB_H

#include "lmms_basics.h"

#include <atomic>

class ThreadableJob
{
public:

	enum class ProcessingState : int
	{
		Unstarted,
		Queued,
		InProgress,
		Done
	};

	ThreadableJob() :
		m_state(ProcessingState::Unstarted)
	{
	}

	inline ProcessingState state() const
	{
		return m_state.load();
	}

	inline void reset()
	{
		m_state = ProcessingState::Unstarted;
	}

	inline void queue()
	{
		m_state = ProcessingState::Queued;
	}

	inline void done()
	{
		m_state = ProcessingState::Done;
	}

	void process()
	{
		auto expected = ProcessingState::Queued;
		if (m_state.compare_exchange_strong(expected, ProcessingState::InProgress))
		{
			doProcessing();
			m_state = ProcessingState::Done;
		}
	}

	virtual bool requiresProcessing() const = 0;

protected:
	virtual void doProcessing() = 0;

	std::atomic<ProcessingState> m_state;
} ;

#endif


code:
/*
 * TimeDisplayWidget.h - widget for displaying current playback time
 *
 * Copyright (c) 2014 Ruben Ibarra
 * Copyright (c) 2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef _TIME_DISPLAY_WIDGET
#define _TIME_DISPLAY_WIDGET

#include <QWidget>
#include <QHBoxLayout>

#include "LcdWidget.h"

class TimeDisplayWidget : public QWidget
{
	Q_OBJECT
public:
	TimeDisplayWidget();
	virtual ~TimeDisplayWidget() = default;

protected:
	void mousePressEvent( QMouseEvent* mouseEvent ) override;

private slots:
	void updateTime();

private:
	enum DisplayModes
	{
		MinutesSeconds,
		BarsTicks,
		DisplayModeCount
	};
	typedef DisplayModes DisplayMode;

	void setDisplayMode( DisplayMode displayMode );

	DisplayMode m_displayMode;
	QHBoxLayout m_spinBoxesLayout;
	LcdWidget m_majorLCD;
	LcdWidget m_minorLCD;
	LcdWidget m_milliSecondsLCD;

} ;

#endif


code:
/*
 * TimeLineWidget.h - class timeLine, representing a time-line with position marker
 *
 * Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TIMELINE_H
#define TIMELINE_H

#include <QWidget>

#include "Song.h"

class QPixmap;
class QToolBar;
class NStateButton;
class TextFloat;
class SongEditor;

class TimeLineWidget : public QWidget, public JournallingObject
{
	Q_OBJECT
public:
	Q_PROPERTY( QColor barLineColor READ getBarLineColor WRITE setBarLineColor )
	Q_PROPERTY( QColor barNumberColor READ getBarNumberColor WRITE setBarNumberColor )
	Q_PROPERTY( QColor inactiveLoopColor READ getInactiveLoopColor WRITE setInactiveLoopColor )
	Q_PROPERTY( QBrush inactiveLoopBrush READ getInactiveLoopBrush WRITE setInactiveLoopBrush )
	Q_PROPERTY( QColor inactiveLoopInnerColor READ getInactiveLoopInnerColor WRITE setInactiveLoopInnerColor )
	Q_PROPERTY( QColor activeLoopColor READ getActiveLoopColor WRITE setActiveLoopColor )
	Q_PROPERTY( QBrush activeLoopBrush READ getActiveLoopBrush WRITE setActiveLoopBrush )
	Q_PROPERTY( QColor activeLoopInnerColor READ getActiveLoopInnerColor WRITE setActiveLoopInnerColor )
	Q_PROPERTY( int loopRectangleVerticalPadding READ getLoopRectangleVerticalPadding WRITE setLoopRectangleVerticalPadding )

	enum AutoScrollStates
	{
		AutoScrollEnabled,
		AutoScrollDisabled
	} ;

	enum LoopPointStates
	{
		LoopPointsDisabled,
		LoopPointsEnabled
	} ;

	enum BehaviourAtStopStates
	{
		BackToZero,
		BackToStart,
		KeepStopPosition
	} ;

	TimeLineWidget(int xoff, int yoff, float ppb, Song::PlayPos & pos,
				const TimePos & begin, Song::PlayModes mode, QWidget * parent);
	virtual ~TimeLineWidget();

	inline QColor const & getBarLineColor() const { return m_barLineColor; }
	inline void setBarLineColor(QColor const & barLineColor) { m_barLineColor = barLineColor; }

	inline QColor const & getBarNumberColor() const { return m_barNumberColor; }
	inline void setBarNumberColor(QColor const & barNumberColor) { m_barNumberColor = barNumberColor; }

	inline QColor const & getInactiveLoopColor() const { return m_inactiveLoopColor; }
	inline void setInactiveLoopColor(QColor const & inactiveLoopColor) { m_inactiveLoopColor = inactiveLoopColor; }

	inline QBrush const & getInactiveLoopBrush() const { return m_inactiveLoopBrush; }
	inline void setInactiveLoopBrush(QBrush const & inactiveLoopBrush) { m_inactiveLoopBrush = inactiveLoopBrush; }

	inline QColor const & getInactiveLoopInnerColor() const { return m_inactiveLoopInnerColor; }
	inline void setInactiveLoopInnerColor(QColor const & inactiveLoopInnerColor) { m_inactiveLoopInnerColor = inactiveLoopInnerColor; }

	inline QColor const & getActiveLoopColor() const { return m_activeLoopColor; }
	inline void setActiveLoopColor(QColor const & activeLoopColor) { m_activeLoopColor = activeLoopColor; }

	inline QBrush const & getActiveLoopBrush() const { return m_activeLoopBrush; }
	inline void setActiveLoopBrush(QBrush const & activeLoopBrush) { m_activeLoopBrush = activeLoopBrush; }

	inline QColor const & getActiveLoopInnerColor() const { return m_activeLoopInnerColor; }
	inline void setActiveLoopInnerColor(QColor const & activeLoopInnerColor) { m_activeLoopInnerColor = activeLoopInnerColor; }

	inline int const & getLoopRectangleVerticalPadding() const { return m_loopRectangleVerticalPadding; }
	inline void setLoopRectangleVerticalPadding(int const & loopRectangleVerticalPadding) { m_loopRectangleVerticalPadding = loopRectangleVerticalPadding; }

	inline Song::PlayPos & pos()
	{
		return( m_pos );
	}

	AutoScrollStates autoScroll() const
	{
		return m_autoScroll;
	}

	BehaviourAtStopStates behaviourAtStop() const
	{
		return m_behaviourAtStop;
	}

	bool loopPointsEnabled() const
	{
		return m_loopPoints == LoopPointsEnabled;
	}

	inline const TimePos & loopBegin() const
	{
		return ( m_loopPos[0] < m_loopPos[1] ) ?
						m_loopPos[0] : m_loopPos[1];
	}

	inline const TimePos & loopEnd() const
	{
		return ( m_loopPos[0] > m_loopPos[1] ) ?
						m_loopPos[0] : m_loopPos[1];
	}

	inline void savePos( const TimePos & pos )
	{
		m_savedPos = pos;
	}
	inline const TimePos & savedPos() const
	{
		return m_savedPos;
	}

	inline void setPixelsPerBar( float ppb )
	{
		m_ppb = ppb;
		update();
	}

	void setXOffset(const int x);

	void addToolButtons(QToolBar* _tool_bar );

	void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
	void loadSettings( const QDomElement & _this ) override;
	inline QString nodeName() const override
	{
		return "timeline";
	}

	inline int markerX( const TimePos & _t ) const
	{
		return m_xOffset + static_cast<int>( ( _t - m_begin ) *
					m_ppb / TimePos::ticksPerBar() );
	}

signals:

	void regionSelectedFromPixels( int, int );
	void selectionFinished();

public slots:
	void updatePosition( const TimePos & );
	void updatePosition()
	{
		updatePosition( TimePos() );
	}
	void toggleAutoScroll( int _n );
	void toggleLoopPoints( int _n );
	void toggleBehaviourAtStop( int _n );

protected:
	void paintEvent( QPaintEvent * _pe ) override;
	void mousePressEvent( QMouseEvent * _me ) override;
	void mouseMoveEvent( QMouseEvent * _me ) override;
	void mouseReleaseEvent( QMouseEvent * _me ) override;

private:
	static QPixmap * s_posMarkerPixmap;

	QColor m_inactiveLoopColor;
	QBrush m_inactiveLoopBrush;
	QColor m_inactiveLoopInnerColor;

	QColor m_activeLoopColor;
	QBrush m_activeLoopBrush;
	QColor m_activeLoopInnerColor;

	int m_loopRectangleVerticalPadding;

	QColor m_barLineColor;
	QColor m_barNumberColor;

	AutoScrollStates m_autoScroll;
	LoopPointStates m_loopPoints;
	BehaviourAtStopStates m_behaviourAtStop;

	bool m_changedPosition;

	int m_xOffset;
	int m_posMarkerX;
	float m_ppb;
	Song::PlayPos & m_pos;
	const TimePos & m_begin;
	const Song::PlayModes m_mode;
	TimePos m_loopPos[2];

	TimePos m_savedPos;

	TextFloat * m_hint;
	int m_initalXSelect;

	enum actions
	{
		NoAction,
		MovePositionMarker,
		MoveLoopBegin,
		MoveLoopEnd,
		SelectSongTCO,
	} m_action;

	int m_moveXOff;

signals:
	void positionChanged( const TimePos & _t );
	void loopPointStateLoaded( int _n );
	void positionMarkerMoved();
	void loadBehaviourAtStop( int _n );

} ;

#endif


code:
/*
 * TimePos.h - declaration of class TimePos which provides data type for
 *             position- and length-variables
 *
 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TIME_POS_H
#define TIME_POS_H

#include <QtGlobal>

#include "lmms_export.h"
#include "lmms_basics.h"

// note: a bar was erroneously called "tact" in older versions of LMMS
const int DefaultTicksPerBar = 192;
const int DefaultStepsPerBar = 16;
const int DefaultBeatsPerBar = DefaultTicksPerBar / DefaultStepsPerBar;

class MeterModel;

/**
	Represents a time signature, in which the numerator is the number of beats
	in a bar, while the denominator is the type of note representing a beat.

	Example: 6/8 means 6 beats in a bar with each beat having a duration of one 8th-note.
*/
class LMMS_EXPORT TimeSig
{
public:
	TimeSig( int num, int denom );
	TimeSig( const MeterModel &model );
	int numerator() const;
	int denominator() const;
private:
	int m_num;
	int m_denom;
};

/**
	Represents a position in time or length of a note or event, in ticks, beats, and bars
*/
class LMMS_EXPORT TimePos
{
public:
	TimePos( const bar_t bar, const tick_t ticks );
	TimePos( const tick_t ticks = 0 );

	TimePos quantize(float) const;
	TimePos toAbsoluteBar() const;

	TimePos& operator+=( const TimePos& time );
	TimePos& operator-=( const TimePos& time );

	// return the bar, rounded down and 0-based
	bar_t getBar() const;
	// return the bar, rounded up and 0-based
	bar_t nextFullBar() const;

	void setTicks( tick_t ticks );
	tick_t getTicks() const;

	operator int() const;

	tick_t ticksPerBeat( const TimeSig &sig ) const;
	// Remainder ticks after bar is removed
	tick_t getTickWithinBar( const TimeSig &sig ) const;
	// Returns the beat position inside the bar, 0-based
	tick_t getBeatWithinBar( const TimeSig &sig ) const;
	// Remainder ticks after bar and beat are removed
	tick_t getTickWithinBeat( const TimeSig &sig ) const;

	// calculate number of frame that are needed this time
	f_cnt_t frames( const float framesPerTick ) const;

	double getTimeInMilliseconds( bpm_t beatsPerMinute ) const;

	static TimePos fromFrames( const f_cnt_t frames, const float framesPerTick );
	static tick_t ticksPerBar();
	static tick_t ticksPerBar( const TimeSig &sig );
	static int stepsPerBar();
	static void setTicksPerBar( tick_t tpt );
	static TimePos stepPosition( int step );
	static double ticksToMilliseconds( tick_t ticks, bpm_t beatsPerMinute );
	static double ticksToMilliseconds( double ticks, bpm_t beatsPerMinute );

private:
	tick_t m_ticks;

	static tick_t s_ticksPerBar;

} ;

#endif


code:
/*
 * ToolButton.h - declaration of class toolButton
 *
 * Copyright (c) 2005-2006 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TOOL_BUTTON_H
#define TOOL_BUTTON_H

#include <QToolButton>
#include <QColor>

class ToolButton : public QToolButton
{
	Q_OBJECT
public:
	ToolButton(const QPixmap & _pixmap, const QString & _tooltip,
			QObject * _receiver=nullptr, const char * _slot=nullptr,
			QWidget * _parent=nullptr);

	inline ToolButton(QWidget * _parent) :
		QToolButton(_parent)
	{ }

	virtual ~ToolButton() = default;

} ;

#endif


code:
/*
 * ToolPlugin.h - declaration of class ToolPlugin, a standard interface for all
 *                tool plugins
 *
 * Copyright (c) 2006-2007 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
 * Copyright (c) 2008-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TOOL_PLUGIN_H
#define TOOL_PLUGIN_H

#include "Plugin.h"

class LMMS_EXPORT ToolPlugin : public Plugin
{
public:
	ToolPlugin( const Descriptor * _descriptor, Model * _parent );
	virtual ~ToolPlugin();

	// instantiate tool-plugin with given name or return NULL
	// on failure
	static ToolPlugin * instantiate( const QString & _plugin_name,
										Model * _parent );

} ;

#endif


code:
/*
 * ToolPluginView.h - declaration of class ToolPluginView
 *
 * Copyright (c) 2006-2007 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
 * Copyright (c) 2008-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TOOL_PLUGIN_VIEW_H
#define TOOL_PLUGIN_VIEW_H

#include "PluginView.h"

class ToolPlugin;

class LMMS_EXPORT ToolPluginView : public PluginView
{
public:
	ToolPluginView( ToolPlugin * _toolPlugin );

} ;

#endif


code:
/*
 * ToolTip.h - namespace toolTip, a tooltip-wrapper for LMMS
 *
 * Copyright (c) 2005-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TOOLTIP_H
#define TOOLTIP_H

#include <qstring.h>

#include "lmms_export.h"

class QWidget;

struct ToolTip
{
	static void LMMS_EXPORT add( QWidget * _w, const QString & _txt );
} ;

#endif


code:
/*
 * Track.h - declaration of Track class
 *
 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TRACK_H
#define TRACK_H

#include <QtCore/QVector>
#include <QColor>

#include "AutomatableModel.h"
#include "JournallingObject.h"
#include "lmms_basics.h"

class TimePos;
class TrackContainer;
class TrackContainerView;
class TrackContentObject;
class TrackView;

/*! The minimum track height in pixels
 *
 * Tracks can be resized by shift-dragging anywhere inside the track
 * display.  This sets the minimum size in pixels for a track.
 */
const int MINIMAL_TRACK_HEIGHT = 32;
const int DEFAULT_TRACK_HEIGHT = 32;

char const *const FILENAME_FILTER = "[\\0000-\x1f\"*/:<>?\\\\|\x7f]";

//! Base-class for all tracks
class LMMS_EXPORT Track : public Model, public JournallingObject
{
	Q_OBJECT
	MM_OPERATORS
	mapPropertyFromModel(bool,isMuted,setMuted,m_mutedModel);
	mapPropertyFromModel(bool,isSolo,setSolo,m_soloModel);
public:
	typedef QVector<TrackContentObject *> tcoVector;

	enum TrackTypes
	{
		InstrumentTrack,
		BBTrack,
		SampleTrack,
		EventTrack,
		VideoTrack,
		AutomationTrack,
		HiddenAutomationTrack,
		NumTrackTypes
	} ;

	Track( TrackTypes type, TrackContainer * tc );
	virtual ~Track();

	static Track * create( TrackTypes tt, TrackContainer * tc );
	static Track * create( const QDomElement & element,
							TrackContainer * tc );
	Track * clone();

	// pure virtual functions
	TrackTypes type() const
	{
		return m_type;
	}

	virtual bool play( const TimePos & start, const fpp_t frames,
						const f_cnt_t frameBase, int tcoNum = -1 ) = 0;

	virtual TrackView * createView( TrackContainerView * view ) = 0;
	virtual TrackContentObject * createTCO( const TimePos & pos ) = 0;

	virtual void saveTrackSpecificSettings( QDomDocument & doc,
						QDomElement & parent ) = 0;
	virtual void loadTrackSpecificSettings( const QDomElement & element ) = 0;

	void saveSettings( QDomDocument & doc, QDomElement & element ) override;
	void loadSettings( const QDomElement & element ) override;

	void setSimpleSerializing()
	{
		m_simpleSerializingMode = true;
	}

	// -- for usage by TrackContentObject only ---------------
	TrackContentObject * addTCO( TrackContentObject * tco );
	void removeTCO( TrackContentObject * tco );
	// -------------------------------------------------------
	void deleteTCOs();

	int numOfTCOs();
	TrackContentObject * getTCO( int tcoNum );
	int getTCONum(const TrackContentObject* tco );

	const tcoVector & getTCOs() const
	{
		return m_trackContentObjects;
	}
	void getTCOsInRange( tcoVector & tcoV, const TimePos & start,
							const TimePos & end );
	void swapPositionOfTCOs( int tcoNum1, int tcoNum2 );

	void createTCOsForBB( int bb );

	void insertBar( const TimePos & pos );
	void removeBar( const TimePos & pos );

	bar_t length() const;

	inline TrackContainer* trackContainer() const
	{
		return m_trackContainer;
	}

	// name-stuff
	virtual const QString & name() const
	{
		return m_name;
	}

	QString displayName() const override
	{
		return name();
	}

	using Model::dataChanged;

	inline int getHeight()
	{
		return m_height >= MINIMAL_TRACK_HEIGHT
			? m_height
			: DEFAULT_TRACK_HEIGHT;
	}
	inline void setHeight( int height )
	{
		m_height = height;
	}

	void lock()
	{
		m_processingLock.lock();
	}
	void unlock()
	{
		m_processingLock.unlock();
	}
	bool tryLock()
	{
		return m_processingLock.tryLock();
	}

	QColor color()
	{
		return m_color;
	}
	bool useColor()
	{
		return m_hasColor;
	}

	BoolModel* getMutedModel();

public slots:
	virtual void setName( const QString & newName )
	{
		m_name = newName;
		emit nameChanged();
	}

	void toggleSolo();

	void trackColorChanged( QColor & c );
	void trackColorReset();

private:
	TrackContainer* m_trackContainer;
	TrackTypes m_type;
	QString m_name;
	int m_height;

protected:
	BoolModel m_mutedModel;
private:
	BoolModel m_soloModel;
	bool m_mutedBeforeSolo;

	bool m_simpleSerializingMode;

	tcoVector m_trackContentObjects;

	QMutex m_processingLock;

	QColor m_color;
	bool m_hasColor;

	friend class TrackView;

signals:
	void destroyedTrack();
	void nameChanged();
	void trackContentObjectAdded( TrackContentObject * );

} ;

#endif


code:
/*
 * TrackContainer.h - base-class for all track-containers like Song-Editor,
 *                    BB-Editor...
 *
 * Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TRACK_CONTAINER_H
#define TRACK_CONTAINER_H

#include <QtCore/QReadWriteLock>

#include "Track.h"
#include "JournallingObject.h"

class AutomationPattern;
class InstrumentTrack;
class TrackContainerView;

class LMMS_EXPORT TrackContainer : public Model, public JournallingObject
{
	Q_OBJECT
public:
	typedef QVector<Track *> TrackList;
	enum TrackContainerTypes
	{
		BBContainer,
		SongContainer
	} ;

	TrackContainer();
	virtual ~TrackContainer();

	void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;

	void loadSettings( const QDomElement & _this ) override;

	virtual AutomationPattern * tempoAutomationPattern()
	{
		return NULL;
	}

	int countTracks( Track::TrackTypes _tt = Track::NumTrackTypes ) const;

	void addTrack( Track * _track );
	void removeTrack( Track * _track );

	virtual void updateAfterTrackAdd();

	void clearAllTracks();

	const TrackList & tracks() const
	{
		return m_tracks;
	}

	bool isEmpty() const;

	static const QString classNodeName()
	{
		return "trackcontainer";
	}

	inline void setType( TrackContainerTypes newType )
	{
		m_TrackContainerType = newType;
	}

	inline TrackContainerTypes type() const
	{
		return m_TrackContainerType;
	}

	virtual AutomatedValueMap automatedValuesAt(TimePos time, int tcoNum = -1) const;

signals:
	void trackAdded( Track * _track );

protected:
	static AutomatedValueMap automatedValuesFromTracks(const TrackList &tracks, TimePos timeStart, int tcoNum = -1);

	mutable QReadWriteLock m_tracksMutex;

private:
	TrackList m_tracks;

	TrackContainerTypes m_TrackContainerType;

	friend class TrackContainerView;
	friend class Track;

} ;

#endif


code:
/*
 * TrackContainerView.h - view-component for TrackContainer
 *
 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TRACK_CONTAINER_VIEW_H
#define TRACK_CONTAINER_VIEW_H

#include <QtCore/QVector>
#include <QScrollArea>
#include <QWidget>
#include <QThread>

#include "JournallingObject.h"
#include "ModelView.h"
#include "Rubberband.h"
#include "TrackView.h"

class QVBoxLayout;

class InstrumentTrack;
class TrackContainer;

class TrackContainerView : public QWidget, public ModelView,
						public JournallingObject,
						public SerializingObjectHook
{
	Q_OBJECT
public:
	TrackContainerView( TrackContainer* tc );
	virtual ~TrackContainerView();

	void saveSettings( QDomDocument & _doc, QDomElement & _this ) override;
	void loadSettings( const QDomElement & _this ) override;

	QScrollArea * contentWidget()
	{
		return m_scrollArea;
	}

	inline const TimePos & currentPosition() const
	{
		return m_currentPosition;
	}

	virtual bool fixedTCOs() const
	{
		return false;
	}

	inline float pixelsPerBar() const
	{
		return m_ppb;
	}

	void setPixelsPerBar( int ppb );

	const TrackView * trackViewAt( const int _y ) const;

	virtual bool allowRubberband() const;

	inline bool rubberBandActive() const
	{
		return m_rubberBand->isEnabled() && m_rubberBand->isVisible();
	}

	inline QVector<selectableObject *> selectedObjects()
	{
		return m_rubberBand->selectedObjects();
	}

	TrackContainer* model()
	{
		return m_tc;
	}

	const TrackContainer* model() const
	{
		return m_tc;
	}

	const QList<TrackView *> & trackViews() const
	{
		return( m_trackViews );
	}

	void moveTrackView( TrackView * trackView, int indexTo );
	void moveTrackViewUp( TrackView * trackView );
	void moveTrackViewDown( TrackView * trackView );
	void scrollToTrackView( TrackView * _tv );

	// -- for usage by trackView only ---------------
	TrackView * addTrackView( TrackView * _tv );
	void removeTrackView( TrackView * _tv );
	// -------------------------------------------------------

	void clearAllTracks();

	QString nodeName() const override
	{
		return "trackcontainerview";
	}

	RubberBand *rubberBand() const;

public slots:
	void realignTracks();
	TrackView * createTrackView( Track * _t );
	void deleteTrackView( TrackView * _tv );

	void dropEvent( QDropEvent * _de ) override;
	void dragEnterEvent( QDragEnterEvent * _dee ) override;

	///
	/// \brief stopRubberBand
	/// Removes the rubber band from display when finished with.
	void stopRubberBand();

protected:
	static const int DEFAULT_PIXELS_PER_BAR = 16;

	void resizeEvent( QResizeEvent * ) override;

	TimePos m_currentPosition;

private:
	enum Actions
	{
		AddTrack,
		RemoveTrack
	} ;

	class scrollArea : public QScrollArea
	{
	public:
		scrollArea( TrackContainerView* parent );
		virtual ~scrollArea();

	protected:
		void wheelEvent( QWheelEvent * _we ) override;

	private:
		TrackContainerView* m_trackContainerView;

	} ;
	friend class TrackContainerView::scrollArea;

	TrackContainer* m_tc;
	typedef QList<TrackView *> trackViewList;
	trackViewList m_trackViews;

	scrollArea * m_scrollArea;
	QVBoxLayout * m_scrollLayout;

	float m_ppb;

	RubberBand * m_rubberBand;

signals:
	void positionChanged( const TimePos & _pos );

} ;

class InstrumentLoaderThread : public QThread
{
	Q_OBJECT
public:
	InstrumentLoaderThread( QObject *parent = 0, InstrumentTrack *it = 0,
							QString name = "" );

	void run() override;

private:
	InstrumentTrack *m_it;
	QString m_name;
	QThread *m_containerThread;
};

#endif


code:
/*
 * TrackConteintObject.h - declaration of TrackContentObject class
 *
 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TRACK_CONTENT_OBJECT_H
#define TRACK_CONTENT_OBJECT_H

#include <QColor>

#include "AutomatableModel.h"
#include "lmms_basics.h"

class Track;
class TrackContentObjectView;
class TrackContainer;
class TrackView;

class LMMS_EXPORT TrackContentObject : public Model, public JournallingObject
{
	Q_OBJECT
	MM_OPERATORS
	mapPropertyFromModel(bool,isMuted,setMuted,m_mutedModel);
	mapPropertyFromModel(bool,isSolo,setSolo,m_soloModel);
public:
	TrackContentObject( Track * track );
	virtual ~TrackContentObject();

	inline Track * getTrack() const
	{
		return m_track;
	}

	inline const QString & name() const
	{
		return m_name;
	}

	inline void setName( const QString & name )
	{
		m_name = name;
		emit dataChanged();
	}

	QString displayName() const override
	{
		return name();
	}

	inline const TimePos & startPosition() const
	{
		return m_startPosition;
	}

	inline TimePos endPosition() const
	{
		const int sp = m_startPosition;
		return sp + m_length;
	}

	inline const TimePos & length() const
	{
		return m_length;
	}

	inline void setAutoResize( const bool r )
	{
		m_autoResize = r;
	}

	inline const bool getAutoResize() const
	{
		return m_autoResize;
	}

	QColor color() const
	{
		return m_color;
	}

	void setColor( const QColor & c )
	{
		m_color = c;
	}

	bool hasColor();

	void useCustomClipColor( bool b );

	bool usesCustomClipColor()
	{
		return m_useCustomClipColor;
	}

	virtual void movePosition( const TimePos & pos );
	virtual void changeLength( const TimePos & length );

	virtual TrackContentObjectView * createView( TrackView * tv ) = 0;

	inline void selectViewOnCreate( bool select )
	{
		m_selectViewOnCreate = select;
	}

	inline bool getSelectViewOnCreate()
	{
		return m_selectViewOnCreate;
	}

	/// Returns true if and only if a->startPosition() < b->startPosition()
	static bool comparePosition(const TrackContentObject* a, const TrackContentObject* b);

	TimePos startTimeOffset() const;
	void setStartTimeOffset( const TimePos &startTimeOffset );

	void updateColor();

	// Will copy the state of a TCO to another TCO
	static void copyStateTo( TrackContentObject *src, TrackContentObject *dst );

public slots:
	void toggleMute();

signals:
	void lengthChanged();
	void positionChanged();
	void destroyedTCO();
	void trackColorChanged();

private:
	enum Actions
	{
		NoAction,
		Move,
		Resize
	} ;

	Track * m_track;
	QString m_name;

	TimePos m_startPosition;
	TimePos m_length;
	TimePos m_startTimeOffset;

	BoolModel m_mutedModel;
	BoolModel m_soloModel;
	bool m_autoResize;

	bool m_selectViewOnCreate;

	QColor m_color;
	bool m_useCustomClipColor;

	friend class TrackContentObjectView;

} ;

#endif


code:
/*
 * TrackContentObjectView.h - declaration of TrackContentObjectView class
 *
 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TRACK_CONTENT_OBJECT_VIEW_H
#define TRACK_CONTENT_OBJECT_VIEW_H

#include <QtCore/QVector>

#include "ModelView.h"
#include "Rubberband.h"
#include "TrackContentObject.h"

class QMenu;
class QContextMenuEvent;

class DataFile;
class TextFloat;
class TrackContentObject;
class TrackView;

class TrackContentObjectView : public selectableObject, public ModelView
{
	Q_OBJECT

// theming qproperties
	Q_PROPERTY( QColor mutedColor READ mutedColor WRITE setMutedColor )
	Q_PROPERTY( QColor mutedBackgroundColor READ mutedBackgroundColor WRITE setMutedBackgroundColor )
	Q_PROPERTY( QColor selectedColor READ selectedColor WRITE setSelectedColor )
	Q_PROPERTY( QColor textColor READ textColor WRITE setTextColor )
	Q_PROPERTY( QColor textBackgroundColor READ textBackgroundColor WRITE setTextBackgroundColor )
	Q_PROPERTY( QColor textShadowColor READ textShadowColor WRITE setTextShadowColor )
	Q_PROPERTY( QColor BBPatternBackground READ BBPatternBackground WRITE setBBPatternBackground )
	Q_PROPERTY( bool gradient READ gradient WRITE setGradient )
	// We have to use a QSize here because using QPoint isn't supported.
	// width -> x, height -> y
	Q_PROPERTY( QSize mouseHotspotHand WRITE setMouseHotspotHand )

public:
	TrackContentObjectView( TrackContentObject * tco, TrackView * tv );
	virtual ~TrackContentObjectView();

	bool fixedTCOs();

	inline TrackContentObject * getTrackContentObject()
	{
		return m_tco;
	}

	inline TrackView * getTrackView()
	{
		return m_trackView;
	}

	// qproperty access func
	QColor mutedColor() const;
	QColor mutedBackgroundColor() const;
	QColor selectedColor() const;
	QColor textColor() const;
	QColor textBackgroundColor() const;
	QColor textShadowColor() const;
	QColor BBPatternBackground() const;
	bool gradient() const;
	void setMutedColor( const QColor & c );
	void setMutedBackgroundColor( const QColor & c );
	void setSelectedColor( const QColor & c );
	void setTextColor( const QColor & c );
	void setTextBackgroundColor( const QColor & c );
	void setTextShadowColor( const QColor & c );
	void setBBPatternBackground( const QColor & c );
	void setGradient( const bool & b );
	void setMouseHotspotHand(const QSize & s);

	// access needsUpdate member variable
	bool needsUpdate();
	void setNeedsUpdate( bool b );

	// Method to get a QVector of TCOs to be affected by a context menu action
	QVector<TrackContentObjectView *> getClickedTCOs();

	// Methods to remove, copy, cut, paste and mute a QVector of TCO views
	void copy( QVector<TrackContentObjectView *> tcovs );
	void cut( QVector<TrackContentObjectView *> tcovs );
	void paste();
	// remove and toggleMute are static because they don't depend
	// being called from a particular TCO view, but can be called anywhere as long
	// as a valid TCO view list is given, while copy/cut require an instance for
	// some metadata to be written to the clipboard.
	static void remove( QVector<TrackContentObjectView *> tcovs );
	static void toggleMute( QVector<TrackContentObjectView *> tcovs );
	static void mergeTCOs(QVector<TrackContentObjectView*> tcovs);

	// Returns true if selection can be merged and false if not
	static bool canMergeSelection(QVector<TrackContentObjectView*> tcovs);

	QColor getColorForDisplay( QColor );

public slots:
	virtual bool close();
	void remove();
	void update() override;

	void changeClipColor();
	void useTrackColor();

protected:
	enum ContextMenuAction
	{
		Remove,
		Cut,
		Copy,
		Paste,
		Mute,
		Merge
	};

	virtual void constructContextMenu( QMenu * )
	{
	}

	void contextMenuEvent( QContextMenuEvent * cme ) override;
	void contextMenuAction( ContextMenuAction action );
	void dragEnterEvent( QDragEnterEvent * dee ) override;
	void dropEvent( QDropEvent * de ) override;
	void leaveEvent( QEvent * e ) override;
	void mousePressEvent( QMouseEvent * me ) override;
	void mouseMoveEvent( QMouseEvent * me ) override;
	void mouseReleaseEvent( QMouseEvent * me ) override;
	void resizeEvent( QResizeEvent * re ) override
	{
		m_needsUpdate = true;
		selectableObject::resizeEvent( re );
	}

	float pixelsPerBar();

	DataFile createTCODataFiles(const QVector<TrackContentObjectView *> & tcos) const;

	virtual void paintTextLabel(QString const & text, QPainter & painter);

protected slots:
	void updateLength();
	void updatePosition();

private:
	enum Actions
	{
		NoAction,
		Move,
		MoveSelection,
		Resize,
		ResizeLeft,
		CopySelection,
		ToggleSelected
	} ;

	static TextFloat * s_textFloat;

	TrackContentObject * m_tco;
	TrackView * m_trackView;
	Actions m_action;
	QPoint m_initialMousePos;
	QPoint m_initialMouseGlobalPos;
	TimePos m_initialTCOPos;
	TimePos m_initialTCOEnd;
	QVector<TimePos> m_initialOffsets;

	TextFloat * m_hint;

// qproperty fields
	QColor m_mutedColor;
	QColor m_mutedBackgroundColor;
	QColor m_selectedColor;
	QColor m_textColor;
	QColor m_textBackgroundColor;
	QColor m_textShadowColor;
	QColor m_BBPatternBackground;
	bool m_gradient;
	QSize m_mouseHotspotHand; // QSize must be used because QPoint isn't supported by property system
	bool m_cursorSetYet;

	bool m_needsUpdate;
	inline void setInitialPos( QPoint pos )
	{
		m_initialMousePos = pos;
		m_initialMouseGlobalPos = mapToGlobal( pos );
		m_initialTCOPos = m_tco->startPosition();
		m_initialTCOEnd = m_initialTCOPos + m_tco->length();
	}
	void setInitialOffsets();

	bool mouseMovedDistance( QMouseEvent * me, int distance );
	TimePos draggedTCOPos( QMouseEvent * me );
} ;

#endif


code:
/*
 * TrackContentWidget.h - declaration of TrackContentWidget class
 *
 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TRACK_CONTENT_WIDGET_H
#define TRACK_CONTENT_WIDGET_H

#include <QWidget>

#include "JournallingObject.h"
#include "TimePos.h"

class QMimeData;

class Track;
class TrackContentObjectView;
class TrackView;

class TrackContentWidget : public QWidget, public JournallingObject
{
	Q_OBJECT

	// qproperties for track background gradients
	Q_PROPERTY( QBrush darkerColor READ darkerColor WRITE setDarkerColor )
	Q_PROPERTY( QBrush lighterColor READ lighterColor WRITE setLighterColor )
	Q_PROPERTY( QBrush gridColor READ gridColor WRITE setGridColor )
	Q_PROPERTY( QBrush embossColor READ embossColor WRITE setEmbossColor )

public:
	TrackContentWidget( TrackView * parent );
	virtual ~TrackContentWidget();

	/*! \brief Updates the background tile pixmap. */
	void updateBackground();

	void addTCOView( TrackContentObjectView * tcov );
	void removeTCOView( TrackContentObjectView * tcov );
	void removeTCOView( int tcoNum )
	{
		if( tcoNum >= 0 && tcoNum < m_tcoViews.size() )
		{
			removeTCOView( m_tcoViews[tcoNum] );
		}
	}

	bool canPasteSelection( TimePos tcoPos, const QDropEvent *de );
	bool canPasteSelection( TimePos tcoPos, const QMimeData *md, bool allowSameBar = false );
	bool pasteSelection( TimePos tcoPos, QDropEvent * de );
	bool pasteSelection( TimePos tcoPos, const QMimeData * md, bool skipSafetyCheck = false );

	TimePos endPosition( const TimePos & posStart );

	// qproperty access methods

	QBrush darkerColor() const;
	QBrush lighterColor() const;
	QBrush gridColor() const;
	QBrush embossColor() const;

	void setDarkerColor( const QBrush & c );
	void setLighterColor( const QBrush & c );
	void setGridColor( const QBrush & c );
	void setEmbossColor( const QBrush & c);

public slots:
	void update();
	void changePosition( const TimePos & newPos = TimePos( -1 ) );

protected:
	enum ContextMenuAction
	{
		Paste
	};

	void contextMenuEvent( QContextMenuEvent * cme ) override;
	void contextMenuAction( QContextMenuEvent * cme, ContextMenuAction action );
	void dragEnterEvent( QDragEnterEvent * dee ) override;
	void dropEvent( QDropEvent * de ) override;
	void mousePressEvent( QMouseEvent * me ) override;
	void paintEvent( QPaintEvent * pe ) override;
	void resizeEvent( QResizeEvent * re ) override;

	QString nodeName() const override
	{
		return "trackcontentwidget";
	}

	void saveSettings( QDomDocument& doc, QDomElement& element ) override
	{
		Q_UNUSED(doc)
		Q_UNUSED(element)
	}

	void loadSettings( const QDomElement& element ) override
	{
		Q_UNUSED(element)
	}

private:
	Track * getTrack();
	TimePos getPosition( int mouseX );

	TrackView * m_trackView;

	typedef QVector<TrackContentObjectView *> tcoViewVector;
	tcoViewVector m_tcoViews;

	QPixmap m_background;

	// qproperty fields
	QBrush m_darkerColor;
	QBrush m_lighterColor;
	QBrush m_gridColor;
	QBrush m_embossColor;
} ;

#endif


code:
/*
 * TrackLabelButton.h - class trackLabelButton
 *
 * Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TRACK_LABEL_BUTTON_H
#define TRACK_LABEL_BUTTON_H

#include <QToolButton>
#include <QLineEdit>

class TrackView;

class TrackRenameLineEdit;

class TrackLabelButton : public QToolButton
{
	Q_OBJECT
public:
	TrackLabelButton( TrackView * _tv, QWidget * _parent );
	virtual ~TrackLabelButton();

public slots:
	void rename();
	void renameFinished();
	void nameChanged();

protected:
	void dragEnterEvent( QDragEnterEvent * _dee ) override;
	void dropEvent( QDropEvent * _de ) override;
	void mousePressEvent( QMouseEvent * _me ) override;
	void mouseDoubleClickEvent( QMouseEvent * _me ) override;
	void mouseReleaseEvent( QMouseEvent * _me ) override;
	void paintEvent( QPaintEvent * _pe ) override;
	void resizeEvent( QResizeEvent * _re ) override;

private:
	TrackView * m_trackView;
	QString m_iconName;
	TrackRenameLineEdit * m_renameLineEdit;
	QRect m_buttonRect;
	QString elideName( const QString &name );

} ;

#endif


code:
/*
 * TrackOperationsWidget.h - declaration of TrackOperationsWidget class
 *
 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TRACK_OPERATIONS_WIDGET_H
#define TRACK_OPERATIONS_WIDGET_H

#include <QWidget>

class QPushButton;

class PixmapButton;
class TrackView;

class TrackOperationsWidget : public QWidget
{
	Q_OBJECT
public:
	TrackOperationsWidget( TrackView * parent );
	~TrackOperationsWidget();

protected:
	void mousePressEvent( QMouseEvent * me ) override;
	void paintEvent( QPaintEvent * pe ) override;

private slots:
	void cloneTrack();
	void removeTrack();
	void updateMenu();
	void changeTrackColor();
	void randomTrackColor();
	void resetTrackColor();
	void useTrackColor();
	void toggleRecording(bool on);
	void recordingOn();
	void recordingOff();
	void clearTrack();

private:
	TrackView * m_trackView;

	QPushButton * m_trackOps;
	PixmapButton * m_muteBtn;
	PixmapButton * m_soloBtn;

	friend class TrackView;

signals:
	void trackRemovalScheduled( TrackView * t );
	void colorChanged( QColor & c );
	void colorParented();
	void colorReset();

} ;

#endif


code:
/*
 * TrackRenameLineEdit.h - class TrackRenameLineEdit
 *
 * Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 * Copyright (c) 2017 Alexandre Almeida <http://m374lx.users.sourceforge.net/>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TRACK_RENAME_LINE_EDIT_H
#define TRACK_RENAME_LINE_EDIT_H

#include <QLineEdit>

class TrackRenameLineEdit : public QLineEdit
{
	Q_OBJECT
public:
	TrackRenameLineEdit( QWidget * parent );
	void show();

protected:
	void keyPressEvent( QKeyEvent * ke ) override;

private:
	QString m_oldName;
} ;

#endif


code:
/*
 * TrackView.h - declaration of TrackView class
 *
 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef TRACK_VIEW_H
#define TRACK_VIEW_H

#include <QWidget>

#include "JournallingObject.h"
#include "ModelView.h"
#include "TrackContentWidget.h"
#include "TrackOperationsWidget.h"

class QMenu;

class FadeButton;
class Track;
class TrackContainerView;
class TrackContentObject;

const int DEFAULT_SETTINGS_WIDGET_WIDTH = 224;
const int TRACK_OP_WIDTH = 78;
// This shaves 150-ish pixels off track buttons,
// ruled from config: ui.compacttrackbuttons
const int DEFAULT_SETTINGS_WIDGET_WIDTH_COMPACT = 96;
const int TRACK_OP_WIDTH_COMPACT = 62;

const int TCO_BORDER_WIDTH = 2;

class TrackView : public QWidget, public ModelView, public JournallingObject
{
	Q_OBJECT
public:
	TrackView( Track * _track, TrackContainerView* tcv );
	virtual ~TrackView();

	inline const Track * getTrack() const
	{
		return m_track;
	}

	inline Track * getTrack()
	{
		return m_track;
	}

	inline TrackContainerView* trackContainerView()
	{
		return m_trackContainerView;
	}

	inline TrackOperationsWidget * getTrackOperationsWidget()
	{
		return &m_trackOperationsWidget;
	}

	inline QWidget * getTrackSettingsWidget()
	{
		return &m_trackSettingsWidget;
	}

	inline TrackContentWidget * getTrackContentWidget()
	{
		return &m_trackContentWidget;
	}

	bool isMovingTrack() const
	{
		return m_action == MoveTrack;
	}

	virtual void update();

	// Create a menu for assigning/creating channels for this track
	// Currently instrument track and sample track supports it
	virtual QMenu * createFxMenu(QString title, QString newFxLabel);

public slots:
	virtual bool close();

protected:
	void modelChanged() override;

	void saveSettings( QDomDocument& doc, QDomElement& element ) override
	{
		Q_UNUSED(doc)
		Q_UNUSED(element)
	}

	void loadSettings( const QDomElement& element ) override
	{
		Q_UNUSED(element)
	}

	QString nodeName() const override
	{
		return "trackview";
	}

	void dragEnterEvent( QDragEnterEvent * dee ) override;
	void dropEvent( QDropEvent * de ) override;
	void mousePressEvent( QMouseEvent * me ) override;
	void mouseMoveEvent( QMouseEvent * me ) override;
	void mouseReleaseEvent( QMouseEvent * me ) override;
	void paintEvent( QPaintEvent * pe ) override;
	void resizeEvent( QResizeEvent * re ) override;

private:
	enum Actions
	{
		NoAction,
		MoveTrack,
		ResizeTrack
	} ;

	Track * m_track;
	TrackContainerView * m_trackContainerView;

	TrackOperationsWidget m_trackOperationsWidget;
	QWidget m_trackSettingsWidget;
	TrackContentWidget m_trackContentWidget;

	Actions m_action;

	virtual FadeButton * getActivityIndicator()
	{
		return nullptr;
	}

	void setIndicatorMute(FadeButton* indicator, bool muted);

	friend class TrackLabelButton;

private slots:
	void createTCOView( TrackContentObject * tco );
	void muteChanged();

} ;

#endif


code:
/*
 * ValueBuffer.h - a container class for passing buffers of model values around
 *
 * Copyright (c) 2014 Vesa Kivimäki <contact/dot/diizy/at/nbl/dot/fi>
 * Copyright (c) 2008-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef VALUE_BUFFER_H
#define VALUE_BUFFER_H

#include <vector>

#include "MemoryManager.h"
#include "lmms_export.h"

class LMMS_EXPORT ValueBuffer : public std::vector<float>
{
	MM_OPERATORS
public:
	ValueBuffer();
	ValueBuffer(int length);

	void fill(float value);

	float value(int offset ) const;

	const float * values() const;
	float * values();

	int length() const;

	void interpolate(float start, float end);
};

#endif


code:
/*
 * VersionedSaveDialog.h - declaration of class VersionedSaveDialog, a file save
 * dialog that provides buttons to increment or decrement a version which is
 * appended to the file name. (e.g. "MyProject-01.mmpz")
 *
 * Copyright (c) 2014 Lukas W <lukaswhl/at/gmail.com>
 *
 * This file is part of LMMS - https://lmms.io
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program (see COPYING); if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 */

#ifndef VERSIONEDSAVEDIALOG_H
#define VERSIONEDSAVEDIALOG_H

#include "FileDialog.h"
#include "Song.h"

class QLineEdit;
class LedCheckBox;

class SaveOptionsWidget : public QWidget {
public:
	SaveOptionsWidget(Song::SaveOptions &saveOptions);

private:
	LedCheckBox *m_discardMIDIConnectionsCheckbox;
};

class VersionedSaveDialog : public FileDialog
{
	Q_OBJECT
public:
	explicit VersionedSaveDialog( QWidget *parent = 0,
								  QWidget *saveOptionsWidget = nullptr,
								  const QString &caption = QString(),
								  const QString &directory = QString(),
								  const QString &filter = QString() );

	// Returns true if file name was changed, returns false if it wasn't
	static bool changeFileNameVersion( QString &fileName, bool increment );
	static bool fileExistsQuery( QString FileName, QString WindowTitle );

public slots:
	void incrementVersion();
	void decrementVersion();
};

#endif // VERSIONEDSAVEDIALOG_H