code:
/*
 * PluginIssue.h - PluginIssue class
 *
 * Copyright (c) 2019 Johannes Lorenz <j.git$$$lorenz-ho.me, $$$=@>
 *
 * 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 PLUGINISSUE_H
#define PLUGINISSUE_H

#include <QDebug>
#include <string>

//! Types of issues that can cause LMMS to not load a plugin
//! LMMS Plugins should use this to indicate errors
enum PluginIssueType
{
	// port flow & type
	unknownPortFlow,
	unknownPortType,
	// channel count
	tooManyInputChannels,
	tooManyOutputChannels,
	tooManyMidiInputChannels,
	tooManyMidiOutputChannels,
	noOutputChannel,
	// port metadata
	portHasNoDef,
	portHasNoMin,
	portHasNoMax,
	minGreaterMax,
	defaultValueNotInRange,
	logScaleMinMissing,
	logScaleMaxMissing,
	logScaleMinMaxDifferentSigns,
	// features
	featureNotSupported, //!< plugin requires functionality LMMS can't offer
	// misc
	badPortType, //!< port type not supported
	blacklisted,
	noIssue
};

//! Issue type bundled with informational string
class PluginIssue
{
	static const char* msgFor(const PluginIssueType& it);

	PluginIssueType m_issueType;
	std::string m_info;

public:
	PluginIssue(PluginIssueType it, std::string msg = std::string())
		: m_issueType(it), m_info(msg)
	{
	}
	PluginIssueType type() const { return m_issueType; }
	bool operator==(const PluginIssue& other) const;
	bool operator<(const PluginIssue& other) const;
	friend QDebug operator<<(QDebug stream, const PluginIssue& iss);
};

QDebug operator<<(QDebug stream, const PluginIssue& iss);

#endif // PLUGINISSUE_H


code:
/*
 * PluginView.h - declaration of class PluginView
 *
 * 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 PLUGIN_VIEW_H
#define PLUGIN_VIEW_H

#include <QWidget>

#include "Plugin.h"
#include "ModelView.h"

class LMMS_EXPORT PluginView  : public QWidget, public ModelView
{
public:
	PluginView( Plugin * _plugin, QWidget * _parent ) :
		QWidget( _parent ),
		ModelView( _plugin, this )
	{
	}

} ;

#endif

repo_name: CYBERDEViL/LMMS

license: mit


code:
/*
 * PositionLine.h - declaration of class PositionLine, a simple widget that
 *                  draws a line, mainly works with TimeLineWidget
 *
 * 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 POSITION_LINE_H
#define POSITION_LINE_H

#include <QWidget>

class PositionLine : public QWidget
{
	Q_OBJECT
	Q_PROPERTY(bool tailGradient MEMBER m_hasTailGradient)
	Q_PROPERTY(QColor lineColor MEMBER m_lineColor)
public:
	PositionLine(QWidget* parent);

public slots:
	void zoomChange(double zoom);

private:
	void paintEvent(QPaintEvent* pe) override;

	bool m_hasTailGradient;
	QColor m_lineColor;
};

#endif


code:
/*
 * PresetPreviewPlayHandle.h - a PlayHandle specialization for playback of a short
 *                             preview of a preset or a file processed by a plugin
 *
 * Copyright (c) 2005-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 PRESET_PREVIEW_PLAY_HANDLE_H
#define PRESET_PREVIEW_PLAY_HANDLE_H

#include "NotePlayHandle.h"

class DataFile;
class InstrumentTrack;
class PreviewTrackContainer;

class LMMS_EXPORT PresetPreviewPlayHandle : public PlayHandle
{
public:
	PresetPreviewPlayHandle( const QString& presetFile, bool loadByPlugin = false, DataFile *dataFile = 0 );
	virtual ~PresetPreviewPlayHandle();

	inline bool affinityMatters() const override
	{
		return true;
	}

	void play( sampleFrame* buffer ) override;
	bool isFinished() const override;

	bool isFromTrack( const Track * _track ) const override;

	static void init();
	static void cleanup();
	static ConstNotePlayHandleList nphsOfInstrumentTrack( const InstrumentTrack* instrumentTrack );

	static bool isPreviewing();

private:
	static PreviewTrackContainer* s_previewTC;

	NotePlayHandle* m_previewNote;

} ;

#endif


code:
/*
 * ProjectJournal.h - declaration of class ProjectJournal
 *
 * Copyright (c) 2006-2010 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 PROJECT_JOURNAL_H
#define PROJECT_JOURNAL_H

#include <QtCore/QHash>
#include <QtCore/QStack>

#include "lmms_basics.h"
#include "DataFile.h"

class JournallingObject;

//! @warning many parts of this class may be rewritten soon
class ProjectJournal
{
public:
	static const int MAX_UNDO_STATES;

	ProjectJournal();
	virtual ~ProjectJournal();

	void undo();
	void redo();

	bool canUndo() const;
	bool canRedo() const;

	void addJournalCheckPoint( JournallingObject *jo );

	bool isJournalling() const
	{
		return m_journalling;
	}

	void setJournalling( const bool _on )
	{
		m_journalling = _on;
	}

	// alloc new ID and register object _obj to it
	jo_id_t allocID( JournallingObject * _obj );

	// if there's already something known about ID _id, but it is currently
	// unused (e.g. after jouralling object was deleted), register object
	// _obj to this id
	void reallocID( const jo_id_t _id, JournallingObject * _obj );

	// make ID _id unused, but keep all global journalling information
	// (order of journalling entries etc.) referring to _id - needed for
	// restoring a journalling object later
	void freeID( const jo_id_t _id )
	{
		reallocID( _id, NULL );
	}

	//! hack, not used when saving a file
	static jo_id_t idToSave( jo_id_t id );
	//! hack, not used when loading a savefile
	static jo_id_t idFromSave( jo_id_t id );

	void clearJournal();
	void stopAllJournalling();
	JournallingObject * journallingObject( const jo_id_t _id )
	{
		if( m_joIDs.contains( _id ) )
		{
			return m_joIDs[_id];
		}
		return NULL;
	}

private:
	typedef QHash<jo_id_t, JournallingObject *> JoIdMap;

	struct CheckPoint
	{
		CheckPoint( jo_id_t initID = 0, const DataFile& initData = DataFile( DataFile::JournalData ) ) :
			joID( initID ),
			data( initData )
		{
		}
		jo_id_t joID;
		DataFile data;
	} ;
	typedef QStack<CheckPoint> CheckPointStack;

	JoIdMap m_joIDs;

	CheckPointStack m_undoCheckPoints;
	CheckPointStack m_redoCheckPoints;

	bool m_journalling;

} ;

#endif


code:
/*
 * ProjectNotes.h - header for project-notes-editor
 *
 * 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 PROJECT_NOTES_H
#define PROJECT_NOTES_H

#include <QMainWindow>
#include <QCloseEvent>

#include "SerializingObject.h"

class QAction;
class QComboBox;
class QTextCharFormat;
class QTextEdit;

class LMMS_EXPORT ProjectNotes : public QMainWindow, public SerializingObject
{
	Q_OBJECT
public:
	ProjectNotes();
	virtual ~ProjectNotes();

	void clear();
	void setText( const QString & _text );

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

	inline QString nodeName() const override
	{
		return "projectnotes";
	}

protected:
	void closeEvent( QCloseEvent * _ce ) override;
	void setupActions();

private slots:
	void textBold();
	void textUnderline();
	void textItalic();
	void textFamily( const QString & _f );
	void textSize( const QString & _p );
	void textColor();
	void textAlign( QAction * _a );

	void formatChanged( const QTextCharFormat & _f );
	void alignmentChanged( int _a );

private:
	QTextEdit * m_edit;
	QAction * m_actionTextBold,
		* m_actionTextUnderline,
		* m_actionTextItalic,
		* m_actionTextColor,
		* m_actionAlignLeft,
		* m_actionAlignCenter,
		* m_actionAlignRight,
		* m_actionAlignJustify;
	QComboBox * m_comboFont;
	QComboBox * m_comboSize;

} ;

#endif


code:
/*
 * ProjectRenderer.h - ProjectRenderer class for easily rendering projects
 *
 * 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 PROJECT_RENDERER_H
#define PROJECT_RENDERER_H

#include "AudioFileDevice.h"
#include "lmmsconfig.h"
#include "Mixer.h"
#include "OutputSettings.h"

#include "lmms_export.h"

class LMMS_EXPORT ProjectRenderer : public QThread
{
	Q_OBJECT
public:
	enum ExportFileFormats: int
	{
		WaveFile,
		FlacFile,
		OggFile,
		MP3File,
		NumFileFormats
	} ;

	struct FileEncodeDevice
	{
		bool isAvailable() const { return m_getDevInst != nullptr; }

		ExportFileFormats m_fileFormat;
		const char * m_description;
		const char * m_extension;
		AudioFileDeviceInstantiaton m_getDevInst;
	} ;

	ProjectRenderer( const Mixer::qualitySettings & _qs,
				const OutputSettings & _os,
				ExportFileFormats _file_format,
				const QString & _out_file );
	virtual ~ProjectRenderer();

	bool isReady() const
	{
		return m_fileDev != NULL;
	}

	static ExportFileFormats getFileFormatFromExtension(
							const QString & _ext );

	static QString getFileExtensionFromFormat( ExportFileFormats fmt );

	static const FileEncodeDevice fileEncodeDevices[];

public slots:
	void startProcessing();
	void abortProcessing();

	void updateConsoleProgress();

signals:
	void progressChanged( int );

private:
	void run() override;

	AudioFileDevice * m_fileDev;
	Mixer::qualitySettings m_qualitySettings;

	volatile int m_progress;
	volatile bool m_abort;

} ;

#endif


code:
/*
 * ProjectVersion.h - version compared in import upgrades
 *
 * Copyright (c) 2007 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
 * Copyright (c) 2015 Tres Finocchiaro <tres.finocchiaro/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 PROJECT_VERSION_H
#define PROJECT_VERSION_H

#include <QtCore/QString>
#include <QtCore/QStringList>

#include <limits>

/*! \brief Version number parsing and comparison
 *
 *  Parses and compares version information.  i.e. "1.0.3" < "1.0.10"
 */
class ProjectVersion
{
public:
	enum CompareType : int { None = 0, Major=1, Minor=2, Release=3, Stage=4, Build=5, All = std::numeric_limits<int>::max() };

	ProjectVersion(QString version, CompareType c = All);
	ProjectVersion(const char * version, CompareType c = All);

	const QString& getVersion() const { return m_version; }
	int getMajor() const { return m_major; }
	int getMinor() const { return m_minor; }
	int getPatch() const { return m_patch; }
	const QStringList& getLabels() const { return m_labels; }
	CompareType getCompareType() const { return m_compareType; }
	ProjectVersion setCompareType(CompareType compareType) { m_compareType = compareType; return * this; }

	static int compare(const ProjectVersion& a, const ProjectVersion& b, CompareType c);
	static int compare(ProjectVersion v1, ProjectVersion v2);

private:
	QString m_version;
	int m_major = 0;
	int m_minor = 0;
	int m_patch = 0;
	QStringList m_labels;
	CompareType m_compareType;
} ;

/*
 * ProjectVersion v. ProjectVersion
 */
inline bool operator<(const ProjectVersion & v1, const ProjectVersion & v2) { return ProjectVersion::compare(v1, v2) < 0; }
inline bool operator>(const ProjectVersion & v1, const ProjectVersion & v2) { return ProjectVersion::compare(v1, v2) > 0; }
inline bool operator<=(const ProjectVersion & v1, const ProjectVersion & v2) { return ProjectVersion::compare(v1, v2) <= 0; }
inline bool operator>=(const ProjectVersion & v1, const ProjectVersion & v2) { return ProjectVersion::compare(v1, v2) >= 0; }
inline bool operator==(const ProjectVersion & v1, const ProjectVersion & v2) { return ProjectVersion::compare(v1, v2) == 0; }
inline bool operator!=(const ProjectVersion & v1, const ProjectVersion & v2) { return ProjectVersion::compare(v1, v2) != 0; }

#endif


code:
#ifndef RECENTPROJECTSMENU_H
#define RECENTPROJECTSMENU_H

#include <QMenu>

class RecentProjectsMenu : public QMenu
{
	Q_OBJECT
public:
	RecentProjectsMenu(QWidget *parent = nullptr);

private slots:
	void fillMenu();
	void openProject(QAction * _action );
};

#endif // RECENTPROJECTSMENU_H


code:
/*
 * RemotePlugin.h - base class providing RPC like mechanisms
 *
 * 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 REMOTE_PLUGIN_H
#define REMOTE_PLUGIN_H

#include "MidiEvent.h"
#include "VstSyncData.h"

#include <atomic>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cassert>

#if !(defined(LMMS_HAVE_SYS_IPC_H) && defined(LMMS_HAVE_SEMAPHORE_H))
#define SYNC_WITH_SHM_FIFO
#define USE_QT_SEMAPHORES

#ifdef LMMS_HAVE_PROCESS_H
#include <process.h>
#endif

#include <QtCore/QtGlobal>
#include <QtCore/QSystemSemaphore>
#endif

#ifdef LMMS_HAVE_SYS_SHM_H
#include <sys/shm.h>

#ifdef LMMS_HAVE_UNISTD_H
#include <unistd.h>
#endif
#else
#define USE_QT_SHMEM

#include <QtCore/QtGlobal>
#include <QtCore/QSharedMemory>

#if !defined(LMMS_HAVE_SYS_TYPES_H) || defined(LMMS_BUILD_WIN32)
typedef int32_t key_t;
#endif
#endif

#ifdef LMMS_HAVE_LOCALE_H
#include <locale.h>
#endif

#ifdef LMMS_HAVE_PTHREAD_H
#include <pthread.h>
#endif

#ifdef BUILD_REMOTE_PLUGIN_CLIENT
#undef LMMS_EXPORT
#define LMMS_EXPORT
#define COMPILE_REMOTE_PLUGIN_BASE

#ifndef SYNC_WITH_SHM_FIFO
#include <sys/socket.h>
#include <sys/un.h>
#endif

#else
#include "lmms_export.h"
#include <QtCore/QMutex>
#include <QtCore/QProcess>
#include <QtCore/QThread>

#ifndef SYNC_WITH_SHM_FIFO
#include <poll.h>
#include <unistd.h>
#endif

#endif

#ifdef SYNC_WITH_SHM_FIFO
// sometimes we need to exchange bigger messages (e.g. for VST parameter dumps)
// so set a usable value here
const int SHM_FIFO_SIZE = 512*1024;

// implements a FIFO inside a shared memory segment
class shmFifo
{
	// need this union to handle different sizes of sem_t on 32 bit
	// and 64 bit platforms
	union sem32_t
	{
		int semKey;
		char fill[32];
	} ;
	struct shmData
	{
		sem32_t dataSem;	// semaphore for locking this
					// FIFO management data
		sem32_t messageSem;	// semaphore for incoming messages
		volatile int32_t startPtr; // current start of FIFO in memory
		volatile int32_t endPtr;   // current end of FIFO in memory
		char data[SHM_FIFO_SIZE];  // actual data
	} ;

public:
	// constructor for master-side
	shmFifo() :
		m_invalid( false ),
		m_master( true ),
		m_shmKey( 0 ),
#ifdef USE_QT_SHMEM
		m_shmObj(),
#else
		m_shmID( -1 ),
#endif
		m_data( NULL ),
		m_dataSem( QString() ),
		m_messageSem( QString() ),
		m_lockDepth( 0 )
	{
#ifdef USE_QT_SHMEM
		do
		{
			m_shmObj.setKey( QString( "%1" ).arg( ++m_shmKey ) );
			m_shmObj.create( sizeof( shmData ) );
		} while( m_shmObj.error() != QSharedMemory::NoError );

		m_data = (shmData *) m_shmObj.data();
#else
		while( ( m_shmID = shmget( ++m_shmKey, sizeof( shmData ),
					IPC_CREAT | IPC_EXCL | 0600 ) ) == -1 )
		{
		}
		m_data = (shmData *) shmat( m_shmID, 0, 0 );
#endif
		assert( m_data != NULL );
		m_data->startPtr = m_data->endPtr = 0;
		static int k = 0;
		m_data->dataSem.semKey = ( getpid()<<10 ) + ++k;
		m_data->messageSem.semKey = ( getpid()<<10 ) + ++k;
		m_dataSem.setKey( QString::number( m_data->dataSem.semKey ),
						1, QSystemSemaphore::Create );
		m_messageSem.setKey( QString::number(
						m_data->messageSem.semKey ),
						0, QSystemSemaphore::Create );
	}

	// constructor for remote-/client-side - use _shm_key for making up
	// the connection to master
	shmFifo( key_t _shm_key ) :
		m_invalid( false ),
		m_master( false ),
		m_shmKey( 0 ),
#ifdef USE_QT_SHMEM
		m_shmObj( QString::number( _shm_key ) ),
#else
		m_shmID( shmget( _shm_key, 0, 0 ) ),
#endif
		m_data( NULL ),
		m_dataSem( QString() ),
		m_messageSem( QString() ),
		m_lockDepth( 0 )
	{
#ifdef USE_QT_SHMEM
		if( m_shmObj.attach() )
		{
			m_data = (shmData *) m_shmObj.data();
		}
#else
		if( m_shmID != -1 )
		{
			m_data = (shmData *) shmat( m_shmID, 0, 0 );
		}
#endif
		assert( m_data != NULL );
		m_dataSem.setKey( QString::number( m_data->dataSem.semKey ) );
		m_messageSem.setKey( QString::number(
						m_data->messageSem.semKey ) );
	}

	~shmFifo()
	{
		// master?
		if( m_master )
		{
#ifndef USE_QT_SHMEM
			shmctl( m_shmID, IPC_RMID, NULL );
#endif
		}
#ifndef USE_QT_SHMEM
		shmdt( m_data );
#endif
	}

	inline bool isInvalid() const
	{
		return m_invalid;
	}

	void invalidate()
	{
		m_invalid = true;
	}

	// do we act as master (i.e. not as remote-process?)
	inline bool isMaster() const
	{
		return m_master;
	}

	// recursive lock
	inline void lock()
	{
		if( !isInvalid() && m_lockDepth.fetch_add( 1 ) == 0 )
		{
			m_dataSem.acquire();
		}
	}

	// recursive unlock
	inline void unlock()
	{
		if( m_lockDepth.fetch_sub( 1 ) <= 1 )
		{
			m_dataSem.release();
		}
	}

	// wait until message-semaphore is available
	inline void waitForMessage()
	{
		if( !isInvalid() )
		{
			m_messageSem.acquire();
		}
	}

	// increase message-semaphore
	inline void messageSent()
	{
		m_messageSem.release();
	}

	inline int32_t readInt()
	{
		int32_t i;
		read( &i, sizeof( i ) );
		return i;
	}

	inline void writeInt( const int32_t & _i )
	{
		write( &_i, sizeof( _i ) );
	}

	inline std::string readString()
	{
		const int len = readInt();
		if( len )
		{
			char * sc = new char[len + 1];
			read( sc, len );
			sc[len] = 0;
			std::string s( sc );
			delete[] sc;
			return s;
		}
		return std::string();
	}

	inline void writeString( const std::string & _s )
	{
		const int len = _s.size();
		writeInt( len );
		write( _s.c_str(), len );
	}

	inline bool messagesLeft()
	{
		if( isInvalid() )
		{
			return false;
		}
		lock();
		const bool empty = ( m_data->startPtr == m_data->endPtr );
		unlock();
		return !empty;
	}

	inline int shmKey() const
	{
		return m_shmKey;
	}

private:
	static inline void fastMemCpy( void * _dest, const void * _src,
							const int _len )
	{
		// calling memcpy() for just an integer is obsolete overhead
		if( _len == 4 )
		{
			*( (int32_t *) _dest ) = *( (int32_t *) _src );
		}
		else
		{
			memcpy( _dest, _src, _len );
		}
	}

	void read( void * _buf, int _len )
	{
		if( isInvalid() )
		{
			memset( _buf, 0, _len );
			return;
		}
		lock();
		while( isInvalid() == false &&
				_len > m_data->endPtr - m_data->startPtr )
		{
			unlock();
#ifndef LMMS_BUILD_WIN32
			usleep( 5 );
#endif
			lock();
		}
		fastMemCpy( _buf, m_data->data + m_data->startPtr, _len );
		m_data->startPtr += _len;
		// nothing left?
		if( m_data->startPtr == m_data->endPtr )
		{
			// then reset to 0
			m_data->startPtr = m_data->endPtr = 0;
		}
		unlock();
	}

	void write( const void * _buf, int _len )
	{
		if( isInvalid() || _len > SHM_FIFO_SIZE )
		{
			return;
		}
		lock();
		while( _len > SHM_FIFO_SIZE - m_data->endPtr )
		{
			// if no space is left, try to move data to front
			if( m_data->startPtr > 0 )
			{
				memmove( m_data->data,
					m_data->data + m_data->startPtr,
					m_data->endPtr - m_data->startPtr );
				m_data->endPtr = m_data->endPtr -
							m_data->startPtr;
				m_data->startPtr = 0;
			}
			unlock();
#ifndef LMMS_BUILD_WIN32
			usleep( 5 );
#endif
			lock();
		}
		fastMemCpy( m_data->data + m_data->endPtr, _buf, _len );
		m_data->endPtr += _len;
		unlock();
	}

	volatile bool m_invalid;
	bool m_master;
	key_t m_shmKey;
#ifdef USE_QT_SHMEM
	QSharedMemory m_shmObj;
#else
	int m_shmID;
#endif
	shmData * m_data;
	QSystemSemaphore m_dataSem;
	QSystemSemaphore m_messageSem;
	std::atomic_int m_lockDepth;

} ;
#endif

enum RemoteMessageIDs
{
	IdUndefined,
	IdHostInfoGotten,
	IdInitDone,
	IdQuit,
	IdSampleRateInformation,
	IdBufferSizeInformation,
	IdInformationUpdated,
	IdMidiEvent,
	IdStartProcessing,
	IdProcessingDone,
	IdChangeSharedMemoryKey,
	IdChangeInputCount,
	IdChangeOutputCount,
	IdChangeInputOutputCount,
	IdShowUI,
	IdHideUI,
	IdToggleUI,
	IdIsUIVisible,
	IdSaveSettingsToString,
	IdSaveSettingsToFile,
	IdLoadSettingsFromString,
	IdLoadSettingsFromFile,
	IdSavePresetFile,
	IdLoadPresetFile,
	IdDebugMessage,
	IdUserBase = 64
} ;

class LMMS_EXPORT RemotePluginBase
{
public:
	struct message
	{
		message() :
			id( IdUndefined ),
			data()
		{
		}

		message( const message & _m ) :
			id( _m.id ),
			data( _m.data )
		{
		}

		message( int _id ) :
			id( _id ),
			data()
		{
		}

		inline message & addString( const std::string & _s )
		{
			data.push_back( _s );
			return *this;
		}

		message & addInt( int _i )
		{
			char buf[32];
			sprintf( buf, "%d", _i );
			data.push_back( std::string( buf ) );
			return *this;
		}

		message & addFloat( float _f )
		{
			char buf[32];
			sprintf( buf, "%f", _f );
			data.push_back( std::string( buf ) );
			return *this;
		}

		inline std::string getString( int _p = 0 ) const
		{
			return data[_p];
		}

#ifndef BUILD_REMOTE_PLUGIN_CLIENT
		inline QString getQString( int _p = 0 ) const
		{
			return QString::fromStdString( getString( _p ) );
		}
#endif

		inline int getInt( int _p = 0 ) const
		{
			return atoi( data[_p].c_str() );
		}

		inline float getFloat( int _p ) const
		{
			return (float) atof( data[_p].c_str() );
		}

		inline bool operator==( const message & _m ) const
		{
			return( id == _m.id );
		}

		int id;

	private:
		std::vector<std::string> data;

		friend class RemotePluginBase;

	} ;

#ifdef SYNC_WITH_SHM_FIFO
	RemotePluginBase( shmFifo * _in, shmFifo * _out );
#else
	RemotePluginBase();
#endif
	virtual ~RemotePluginBase();

#ifdef SYNC_WITH_SHM_FIFO
	void reset( shmFifo *in, shmFifo *out )
	{
		delete m_in;
		delete m_out;
		m_in = in;
		m_out = out;
	}
#endif

	int sendMessage( const message & _m );
	message receiveMessage();

	inline bool isInvalid() const
	{
#ifdef SYNC_WITH_SHM_FIFO
		return m_in->isInvalid() || m_out->isInvalid();
#else
		return m_invalid;
#endif
	}

	message waitForMessage( const message & _m,
						bool _busy_waiting = false );

	inline message fetchAndProcessNextMessage()
	{
		message m = receiveMessage();
		processMessage( m );
		return m;
	}

#ifndef SYNC_WITH_SHM_FIFO
	inline int32_t readInt()
	{
		int32_t i;
		read( &i, sizeof( i ) );
		return i;
	}

	inline void writeInt( const int32_t & _i )
	{
		write( &_i, sizeof( _i ) );
	}

	inline std::string readString()
	{
		const int len = readInt();
		if( len )
		{
			char * sc = new char[len + 1];
			read( sc, len );
			sc[len] = 0;
			std::string s( sc );
			delete[] sc;
			return s;
		}
		return std::string();
	}

	inline void writeString( const std::string & _s )
	{
		const int len = _s.size();
		writeInt( len );
		write( _s.c_str(), len );
	}
#endif

#ifndef BUILD_REMOTE_PLUGIN_CLIENT
	inline bool messagesLeft()
	{
#ifdef SYNC_WITH_SHM_FIFO
		return m_in->messagesLeft();
#else
		struct pollfd pollin;
		pollin.fd = m_socket;
		pollin.events = POLLIN;

		if ( poll( &pollin, 1, 0 ) == -1 )
		{
			qWarning( "Unexpected poll error." );
		}
		return pollin.revents & POLLIN;
#endif
	}

	inline void fetchAndProcessAllMessages()
	{
		while( messagesLeft() )
		{
			fetchAndProcessNextMessage();
		}
	}

	static bool isMainThreadWaiting()
	{
		return waitDepthCounter() > 0;
	}
#endif

	virtual bool processMessage( const message & _m ) = 0;

protected:
#ifdef SYNC_WITH_SHM_FIFO
	inline const shmFifo * in() const
	{
		return m_in;
	}

	inline const shmFifo * out() const
	{
		return m_out;
	}
#endif

	inline void invalidate()
	{
#ifdef SYNC_WITH_SHM_FIFO
		m_in->invalidate();
		m_out->invalidate();
		m_in->messageSent();
#else
		m_invalid = true;
#endif
	}

#ifndef SYNC_WITH_SHM_FIFO
	int m_socket;
#endif

private:
#ifndef BUILD_REMOTE_PLUGIN_CLIENT
	static int & waitDepthCounter()
	{
		static int waitDepth = 0;
		return waitDepth;
	}
#endif

#ifdef SYNC_WITH_SHM_FIFO
	shmFifo * m_in;
	shmFifo * m_out;
#else
	void read( void * _buf, int _len )
	{
		if( isInvalid() )
		{
			memset( _buf, 0, _len );
			return;
		}
		char * buf = (char *) _buf;
		int remaining = _len;
		while ( remaining )
		{
			ssize_t nread = ::read( m_socket, buf, remaining );
			switch ( nread )
			{
				case -1:
					fprintf( stderr,
						"Error while reading.\n" );
				case 0:
					invalidate();
					memset( _buf, 0, _len );
					return;
			}
			buf += nread;
			remaining -= nread;
		}
	}

	void write( const void * _buf, int _len )
	{
		if( isInvalid() )
		{
			return;
		}
		const char * buf = (const char *) _buf;
		int remaining = _len;
		while ( remaining )
		{
			ssize_t nwritten = ::write( m_socket, buf, remaining );
			switch ( nwritten )
			{
				case -1:
					fprintf( stderr,
						"Error while writing.\n" );
				case 0:
					invalidate();
					return;
			}
			buf += nwritten;
			remaining -= nwritten;
		}
	}

	bool m_invalid;

	pthread_mutex_t m_receiveMutex;
	pthread_mutex_t m_sendMutex;
#endif

} ;

#ifndef BUILD_REMOTE_PLUGIN_CLIENT

class RemotePlugin;

class ProcessWatcher : public QThread
{
	Q_OBJECT
public:
	ProcessWatcher( RemotePlugin * );
	virtual ~ProcessWatcher() = default;

	void stop()
	{
		m_quit = true;
		quit();
	}

	void reset()
	{
		m_quit = false;
	}

private:
	void run() override;

	RemotePlugin * m_plugin;
	volatile bool m_quit;

} ;

class LMMS_EXPORT RemotePlugin : public QObject, public RemotePluginBase
{
	Q_OBJECT
public:
	RemotePlugin();
	virtual ~RemotePlugin();

	inline bool isRunning()
	{
#ifdef DEBUG_REMOTE_PLUGIN
		return true;
#else
		return m_process.state() != QProcess::NotRunning;
#endif
	}

	bool init( const QString &pluginExecutable, bool waitForInitDoneMsg, QStringList extraArgs = {} );

	inline void waitForHostInfoGotten()
	{
		m_failed = waitForMessage( IdHostInfoGotten ).id
							!= IdHostInfoGotten;
	}

	inline void waitForInitDone( bool _busyWaiting = true )
	{
		m_failed = waitForMessage( IdInitDone, _busyWaiting ).id != IdInitDone;
	}

	bool processMessage( const message & _m ) override;

	bool process( const sampleFrame * _in_buf, sampleFrame * _out_buf );

	void processMidiEvent( const MidiEvent&, const f_cnt_t _offset );

	void updateSampleRate( sample_rate_t _sr )
	{
		lock();
		sendMessage( message( IdSampleRateInformation ).addInt( _sr ) );
		waitForMessage( IdInformationUpdated, true );
		unlock();
	}

	virtual void toggleUI()
	{
		lock();
		sendMessage( IdToggleUI );
		unlock();
	}

	int isUIVisible()
	{
		lock();
		sendMessage( IdIsUIVisible );
		unlock();
		message m = waitForMessage( IdIsUIVisible );
		return m.id != IdIsUIVisible ? -1 : m.getInt() ? 1 : 0;
	}

	inline bool failed() const
	{
		return m_failed;
	}

	inline void lock()
	{
		m_commMutex.lock();
	}

	inline void unlock()
	{
		m_commMutex.unlock();
	}

public slots:
	virtual void showUI();
	virtual void hideUI();

protected:
	inline void setSplittedChannels( bool _on )
	{
		m_splitChannels = _on;
	}

	bool m_failed;
private:
	void resizeSharedProcessingMemory();

	QProcess m_process;
	ProcessWatcher m_watcher;

	QString m_exec;
	QStringList m_args;

	QMutex m_commMutex;
	bool m_splitChannels;
#ifdef USE_QT_SHMEM
	QSharedMemory m_shmObj;
#else
	int m_shmID;
#endif
	size_t m_shmSize;
	float * m_shm;

	int m_inputCount;
	int m_outputCount;

#ifndef SYNC_WITH_SHM_FIFO
	int m_server;
	QString m_socketFile;
#endif

	friend class ProcessWatcher;

private slots:
	void processFinished( int exitCode, QProcess::ExitStatus exitStatus );
	void processErrored(QProcess::ProcessError err );
} ;

#endif

#ifdef BUILD_REMOTE_PLUGIN_CLIENT

class RemotePluginClient : public RemotePluginBase
{
public:
#ifdef SYNC_WITH_SHM_FIFO
	RemotePluginClient( key_t _shm_in, key_t _shm_out );
#else
	RemotePluginClient( const char * socketPath );
#endif
	virtual ~RemotePluginClient();
#ifdef USE_QT_SHMEM
	VstSyncData * getQtVSTshm();
#endif
	virtual bool processMessage( const message & _m );

	virtual void process( const sampleFrame * _in_buf,
					sampleFrame * _out_buf ) = 0;

	virtual void processMidiEvent( const MidiEvent&, const f_cnt_t /* _offset */ )
	{
	}

	inline float * sharedMemory()
	{
		return m_shm;
	}

	virtual void updateSampleRate()
	{
	}

	virtual void updateBufferSize()
	{
	}

	inline sample_rate_t sampleRate() const
	{
		return m_sampleRate;
	}

	inline fpp_t bufferSize() const
	{
		return m_bufferSize;
	}

	void setInputCount( int _i )
	{
		m_inputCount = _i;
		sendMessage( message( IdChangeInputCount ).addInt( _i ) );
	}

	void setOutputCount( int _i )
	{
		m_outputCount = _i;
		sendMessage( message( IdChangeOutputCount ).addInt( _i ) );
	}

	void setInputOutputCount( int i, int o )
	{
		m_inputCount = i;
		m_outputCount = o;
		sendMessage( message( IdChangeInputOutputCount )
				.addInt( i )
				.addInt( o ) );
	}

	virtual int inputCount() const
	{
		return m_inputCount;
	}

	virtual int outputCount() const
	{
		return m_outputCount;
	}

	void debugMessage( const std::string & _s )
	{
		sendMessage( message( IdDebugMessage ).addString( _s ) );
	}

private:
	void setShmKey( key_t _key, int _size );
	void doProcessing();

#ifdef USE_QT_SHMEM
	QSharedMemory m_shmObj;
	QSharedMemory m_shmQtID;
#endif
	VstSyncData * m_vstSyncData;
	float * m_shm;

	int m_inputCount;
	int m_outputCount;

	sample_rate_t m_sampleRate;
	fpp_t m_bufferSize;

} ;

#endif

#ifdef COMPILE_REMOTE_PLUGIN_BASE

#ifndef BUILD_REMOTE_PLUGIN_CLIENT
#include <QtCore/QCoreApplication>
#endif

#ifdef SYNC_WITH_SHM_FIFO
RemotePluginBase::RemotePluginBase( shmFifo * _in, shmFifo * _out ) :
	m_in( _in ),
	m_out( _out )
#else
RemotePluginBase::RemotePluginBase() :
	m_socket( -1 ),
	m_invalid( false )
#endif
{
#ifdef LMMS_HAVE_LOCALE_H
	// make sure, we're using common ways to print/scan
	// floats to/from strings (',' vs. '.' for decimal point etc.)
	setlocale( LC_NUMERIC, "C" );
#endif
#ifndef SYNC_WITH_SHM_FIFO
	pthread_mutex_init( &m_receiveMutex, NULL );
	pthread_mutex_init( &m_sendMutex, NULL );
#endif
}

RemotePluginBase::~RemotePluginBase()
{
#ifdef SYNC_WITH_SHM_FIFO
	delete m_in;
	delete m_out;
#else
	pthread_mutex_destroy( &m_receiveMutex );
	pthread_mutex_destroy( &m_sendMutex );
#endif
}

int RemotePluginBase::sendMessage( const message & _m )
{
#ifdef SYNC_WITH_SHM_FIFO
	m_out->lock();
	m_out->writeInt( _m.id );
	m_out->writeInt( _m.data.size() );
	int j = 8;
	for( unsigned int i = 0; i < _m.data.size(); ++i )
	{
		m_out->writeString( _m.data[i] );
		j += 4 + _m.data[i].size();
	}
	m_out->unlock();
	m_out->messageSent();
#else
	pthread_mutex_lock( &m_sendMutex );
	writeInt( _m.id );
	writeInt( _m.data.size() );
	int j = 8;
	for( unsigned int i = 0; i < _m.data.size(); ++i )
	{
		writeString( _m.data[i] );
		j += 4 + _m.data[i].size();
	}
	pthread_mutex_unlock( &m_sendMutex );
#endif

	return j;
}

RemotePluginBase::message RemotePluginBase::receiveMessage()
{
#ifdef SYNC_WITH_SHM_FIFO
	m_in->waitForMessage();
	m_in->lock();
	message m;
	m.id = m_in->readInt();
	const int s = m_in->readInt();
	for( int i = 0; i < s; ++i )
	{
		m.data.push_back( m_in->readString() );
	}
	m_in->unlock();
#else
	pthread_mutex_lock( &m_receiveMutex );
	message m;
	m.id = readInt();
	const int s = readInt();
	for( int i = 0; i < s; ++i )
	{
		m.data.push_back( readString() );
	}
	pthread_mutex_unlock( &m_receiveMutex );
#endif
	return m;
}

RemotePluginBase::message RemotePluginBase::waitForMessage(
							const message & _wm,
							bool _busy_waiting )
{
#ifndef BUILD_REMOTE_PLUGIN_CLIENT
	if( _busy_waiting )
	{
		// No point processing events outside of the main thread
		_busy_waiting = QThread::currentThread() ==
					QCoreApplication::instance()->thread();
	}

	struct WaitDepthCounter
	{
		WaitDepthCounter( int & depth, bool busy ) :
			m_depth( depth ),
			m_busy( busy )
		{
			if( m_busy ) { ++m_depth; }
		}

		~WaitDepthCounter()
		{
			if( m_busy ) { --m_depth; }
		}

		int & m_depth;
		bool m_busy;
	};

	WaitDepthCounter wdc( waitDepthCounter(), _busy_waiting );
#endif
	while( !isInvalid() )
	{
#ifndef BUILD_REMOTE_PLUGIN_CLIENT
		if( _busy_waiting && !messagesLeft() )
		{
			QCoreApplication::processEvents(
				QEventLoop::ExcludeUserInputEvents, 50 );
			continue;
		}
#endif
		message m = receiveMessage();
		processMessage( m );
		if( m.id == _wm.id )
		{
			return m;
		}
		else if( m.id == IdUndefined )
		{
			return m;
		}
	}

	return message();
}

#endif

#ifdef BUILD_REMOTE_PLUGIN_CLIENT

#ifdef SYNC_WITH_SHM_FIFO
RemotePluginClient::RemotePluginClient( key_t _shm_in, key_t _shm_out ) :
	RemotePluginBase( new shmFifo( _shm_in ), new shmFifo( _shm_out ) ),
#else
RemotePluginClient::RemotePluginClient( const char * socketPath ) :
	RemotePluginBase(),
#endif
#ifdef USE_QT_SHMEM
	m_shmObj(),
	m_shmQtID( "/usr/bin/lmms" ),
#endif
	m_vstSyncData( NULL ),
	m_shm( NULL ),
	m_inputCount( 0 ),
	m_outputCount( 0 ),
	m_sampleRate( 44100 ),
	m_bufferSize( 0 )
{
#ifndef SYNC_WITH_SHM_FIFO
	struct sockaddr_un sa;
	sa.sun_family = AF_LOCAL;

	size_t length = strlen( socketPath );
	if ( length >= sizeof sa.sun_path )
	{
		length = sizeof sa.sun_path - 1;
		fprintf( stderr, "Socket path too long.\n" );
	}
	memcpy( sa.sun_path, socketPath, length );
	sa.sun_path[length] = '\0';

	m_socket = socket( PF_LOCAL, SOCK_STREAM, 0 );
	if ( m_socket == -1 )
	{
		fprintf( stderr, "Could not connect to local server.\n" );
	}
	if ( ::connect( m_socket, (struct sockaddr *) &sa, sizeof sa ) == -1 )
	{
		fprintf( stderr, "Could not connect to local server.\n" );
	}
#endif

#ifdef USE_QT_SHMEM
	if( m_shmQtID.attach( QSharedMemory::ReadOnly ) )
	{
		m_vstSyncData = (VstSyncData *) m_shmQtID.data();
		m_bufferSize = m_vstSyncData->m_bufferSize;
		m_sampleRate = m_vstSyncData->m_sampleRate;
		sendMessage( IdHostInfoGotten );
		return;
	}
#else
	key_t key;
	int m_shmID;

	if( ( key = ftok( VST_SNC_SHM_KEY_FILE, 'R' ) ) == -1 )
	{
		perror( "RemotePluginClient::ftok" );
	}
	else
	{	// connect to shared memory segment
		if( ( m_shmID = shmget( key, 0, 0 ) ) == -1 )
		{
			perror( "RemotePluginClient::shmget" );
		}
		else
		{	// attach segment
			m_vstSyncData = (VstSyncData *)shmat(m_shmID, 0, 0);
			if( m_vstSyncData == (VstSyncData *)( -1 ) )
			{
				perror( "RemotePluginClient::shmat" );
			}
			else
			{
				m_bufferSize = m_vstSyncData->m_bufferSize;
				m_sampleRate = m_vstSyncData->m_sampleRate;
				sendMessage( IdHostInfoGotten );

				// detach segment
				if( shmdt(m_vstSyncData) == -1 )
				{
					perror("RemotePluginClient::shmdt");
				}
				return;
			}
		}
	}
#endif

	// if attaching shared memory fails
	sendMessage( IdSampleRateInformation );
	sendMessage( IdBufferSizeInformation );
	if( waitForMessage( IdBufferSizeInformation ).id
						!= IdBufferSizeInformation )
	{
		fprintf( stderr, "Could not get buffer size information\n" );
	}
	sendMessage( IdHostInfoGotten );
}

RemotePluginClient::~RemotePluginClient()
{
#ifdef USE_QT_SHMEM
	m_shmQtID.detach();
#endif
	sendMessage( IdQuit );

#ifndef USE_QT_SHMEM
	shmdt( m_shm );
#endif

#ifndef SYNC_WITH_SHM_FIFO
	if ( close( m_socket ) == -1)
	{
		fprintf( stderr, "Error freeing resources.\n" );
	}
#endif
}

#ifdef USE_QT_SHMEM
VstSyncData * RemotePluginClient::getQtVSTshm()
{
	return m_vstSyncData;
}
#endif

bool RemotePluginClient::processMessage( const message & _m )
{
	message reply_message( _m.id );
	bool reply = false;
	switch( _m.id )
	{
		case IdUndefined:
			return false;

		case IdSampleRateInformation:
			m_sampleRate = _m.getInt();
			updateSampleRate();
			reply_message.id = IdInformationUpdated;
			reply = true;
			break;

		case IdBufferSizeInformation:
			// Should LMMS gain the ability to change buffer size
			// without a restart, it must wait for this message to
			// complete processing or else risk VST crashes
			m_bufferSize = _m.getInt();
			updateBufferSize();
			break;

		case IdQuit:
			return false;

		case IdMidiEvent:
			processMidiEvent(
				MidiEvent( static_cast<MidiEventTypes>(
							_m.getInt( 0 ) ),
						_m.getInt( 1 ),
						_m.getInt( 2 ),
						_m.getInt( 3 ) ),
							_m.getInt( 4 ) );
			break;

		case IdStartProcessing:
			doProcessing();
			reply_message.id = IdProcessingDone;
			reply = true;
			break;

		case IdChangeSharedMemoryKey:
			setShmKey( _m.getInt( 0 ), _m.getInt( 1 ) );
			break;

		case IdInitDone:
			break;

		default:
		{
			char buf[64];
			sprintf( buf, "undefined message: %d\n", (int) _m.id );
			debugMessage( buf );
			break;
		}
	}
	if( reply )
	{
		sendMessage( reply_message );
	}

	return true;
}

void RemotePluginClient::setShmKey( key_t _key, int _size )
{
#ifdef USE_QT_SHMEM
	m_shmObj.setKey( QString::number( _key ) );
	if( m_shmObj.attach() || m_shmObj.error() == QSharedMemory::NoError )
	{
		m_shm = (float *) m_shmObj.data();
	}
	else
	{
		char buf[64];
		sprintf( buf, "failed getting shared memory: %d\n", m_shmObj.error() );
		debugMessage( buf );
	}
#else
	if( m_shm != NULL )
	{
		shmdt( m_shm );
		m_shm = NULL;
	}

	// only called for detaching SHM?
	if( _key == 0 )
	{
		return;
	}

	int shm_id = shmget( _key, _size, 0 );
	if( shm_id == -1 )
	{
		debugMessage( "failed getting shared memory\n" );
	}
	else
	{
		m_shm = (float *) shmat( shm_id, 0, 0 );
	}
#endif
}

void RemotePluginClient::doProcessing()
{
	if( m_shm != NULL )
	{
		process( (sampleFrame *)( m_inputCount > 0 ? m_shm : NULL ),
				(sampleFrame *)( m_shm +
					( m_inputCount*m_bufferSize ) ) );
	}
	else
	{
		debugMessage( "doProcessing(): have no shared memory!\n" );
	}
}

#endif

#define QSTR_TO_STDSTR(s)	std::string( s.toUtf8().constData() )

#endif


code:
/*
 * RenameDialog.h - declaration of class renameDialog, a simple dialog for
 *                   changing the content of a string
 *
 * Copyright (c) 2004-2005 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 RENAME_DIALOG_H
#define RENAME_DIALOG_H

#include <QDialog>

class QLineEdit;

class RenameDialog : public QDialog
{
	Q_OBJECT
public:
	RenameDialog( QString & _string );
	~RenameDialog();

protected:
	void keyPressEvent( QKeyEvent * _ke ) override;
	void resizeEvent(QResizeEvent * event) override;

protected slots:
	void textChanged( const QString & _new_string );

private:
	QString & m_stringToEdit;
	QString m_originalString;
	QLineEdit * m_stringLE;

} ;

#endif


code:
/*
 * RenderManager.h - Provides a uniform interface for rendering the project or
 *                   individual tracks for the CLI and GUI.
 *
 * Copyright (c) 2015 Ryan Roden-Corrent <ryan/at/rcorre.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 RENDER_MANAGER_H
#define RENDER_MANAGER_H

#include <memory>

#include "ProjectRenderer.h"
#include "OutputSettings.h"

class RenderManager : public QObject
{
	Q_OBJECT
public:
	RenderManager(
		const Mixer::qualitySettings & qualitySettings,
		const OutputSettings & outputSettings,
		ProjectRenderer::ExportFileFormats fmt,
		QString outputPath);

	virtual ~RenderManager();

	/// Export all unmuted tracks into a single file
	void renderProject();

	/// Export all unmuted tracks into individual file
	void renderTracks();

	void abortProcessing();

signals:
	void progressChanged( int );
	void finished();

private slots:
	void renderNextTrack();
	void updateConsoleProgress();

private:
	QString pathForTrack( const Track *track, int num );
	void restoreMutedState();

	void render( QString outputPath );

	const Mixer::qualitySettings m_qualitySettings;
	const Mixer::qualitySettings m_oldQualitySettings;
	const OutputSettings m_outputSettings;
	ProjectRenderer::ExportFileFormats m_format;
	QString m_outputPath;

	std::unique_ptr<ProjectRenderer> m_activeRenderer;

	QVector<Track*> m_tracksToRender;
	QVector<Track*> m_unmuted;
} ;

#endif


code:
/*
 * RingBuffer.h - an effective and flexible implementation of a ringbuffer for LMMS
 *
 * Copyright (c) 2014 Vesa Kivimäki
 * Copyright (c) 2005-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 RINGBUFFER_H
#define RINGBUFFER_H

#include <QObject>
#include "lmms_basics.h"
#include "lmms_math.h"
#include "MemoryManager.h"

/** \brief A basic LMMS ring buffer for single-thread use. For thread and realtime safe alternative see LocklessRingBuffer.
*/
class LMMS_EXPORT RingBuffer : public QObject
{
	Q_OBJECT
	MM_OPERATORS
public:
/** \brief Constructs a ringbuffer of specified size, will not care about samplerate changes
 * 	\param size The size of the buffer in frames. The actual size will be size + period size
 */
	RingBuffer( f_cnt_t size );

/** \brief Constructs a ringbuffer of specified samplerate-dependent size, which will be updated when samplerate changes
 * 	\param size The size of the buffer in milliseconds. The actual size will be size + period size
 */
	RingBuffer( float size );
	virtual ~RingBuffer();

////////////////////////////////////
//       Provided functions       //
////////////////////////////////////

// utility functions

/** \brief Clears the ringbuffer of any data and resets the position to 0
 */
	void reset();

/** \brief Changes the size of the ringbuffer. Clears all data.
 * 	\param size New size in frames
 */
	void changeSize( f_cnt_t size );

/** \brief Changes the size of the ringbuffer. Clears all data.
 * 	\param size New size in milliseconds
 */
	void changeSize( float size );

/** \brief Sets whether the ringbuffer size is adjusted for samplerate when samplerate changes
 *	\param b True if samplerate should affect buffer size
 */
	void setSamplerateAware( bool b );

// position adjustment functions

/** \brief Advances the position by one period
 */
	void advance();

/** \brief Moves position forwards/backwards by an amount of frames
 * 	\param amount Number of frames to move, may be negative
 */
	void movePosition( f_cnt_t amount );

/** \brief Moves position forwards/backwards by an amount of milliseconds
 * 	\param amount Number of milliseconds to move, may be negative
 */
	void movePosition( float amount );

// read functions

/** \brief Destructively reads a period-sized buffer from the current position, writes it
 * 	to a specified destination, and advances the position by one period
 * 	\param dst Destination pointer
 */
	void pop( sampleFrame * dst );

// note: ringbuffer position is unaffected by all other read functions beside pop()

/** \brief Reads a period-sized buffer from the ringbuffer and writes it to a specified destination
 * 	\param dst Destination pointer
 * 	\param offset Offset in frames against current position, may be negative
 */
	void read( sampleFrame * dst, f_cnt_t offset=0 );

/** \brief Reads a period-sized buffer from the ringbuffer and writes it to a specified destination
 * 	\param dst Destination pointer
 * 	\param offset Offset in milliseconds against current position, may be negative
 */
	void read( sampleFrame * dst, float offset );

/** \brief Reads a buffer of specified size from the ringbuffer and writes it to a specified destination
 * 	\param dst Destination pointer
 * 	\param offset Offset in frames against current position, may be negative
 * 	\param length Length in frames of the buffer to read - must not be higher than the size of the ringbuffer!
 */
	void read( sampleFrame * dst, f_cnt_t offset, f_cnt_t length );

/** \brief Reads a buffer of specified size from the ringbuffer and writes it to a specified destination
 * 	\param dst Destination pointer
 * 	\param offset Offset in milliseconds against current position, may be negative
 * 	\param length Length in frames of the buffer to read - must not be higher than the size of the ringbuffer!
 */
	void read( sampleFrame * dst, float offset, f_cnt_t length );

// write functions

/** \brief Writes a buffer of sampleframes to the ringbuffer at specified position
 * 	\param src Pointer to the source buffer
 * 	\param offset Offset in frames against current position, may *NOT* be negative
 * 	\param length Length of the source buffer, if zero, period size is used - must not be higher than the size of the ringbuffer!
 */
	void write( sampleFrame * src, f_cnt_t offset=0, f_cnt_t length=0 );

/** \brief Writes a buffer of sampleframes to the ringbuffer at specified position
 * 	\param src Pointer to the source buffer
 * 	\param offset Offset in milliseconds against current position, may *NOT* be negative
 * 	\param length Length of the source buffer, if zero, period size is used - must not be higher than the size of the ringbuffer!
 */
	void write( sampleFrame * src, float offset, f_cnt_t length=0 );

/** \brief Mixes a buffer of sampleframes additively to the ringbuffer at specified position
 * 	\param src Pointer to the source buffer
 * 	\param offset Offset in frames against current position, may *NOT* be negative
 * 	\param length Length of the source buffer, if zero, period size is used - must not be higher than the size of the ringbuffer!
 */
	void writeAdding( sampleFrame * src, f_cnt_t offset=0, f_cnt_t length=0 );

/** \brief Mixes a buffer of sampleframes additively to the ringbuffer at specified position
 * 	\param src Pointer to the source buffer
 * 	\param offset Offset in milliseconds against current position, may *NOT* be negative
 * 	\param length Length of the source buffer, if zero, period size is used - must not be higher than the size of the ringbuffer!
 */
	void writeAdding( sampleFrame * src, float offset, f_cnt_t length=0 );

/** \brief Mixes a buffer of sampleframes additively to the ringbuffer at specified position, with
 * 	a specified multiplier applied to the frames
 * 	\param	src Pointer to the source buffer
 * 	\param offset Offset in frames against current position, may *NOT* be negative
 * 	\param length Length of the source buffer, if zero, period size is used - must not be higher than the size of the ringbuffer!
 * 	\param level Multiplier applied to the frames before they're written to the ringbuffer
 */
	void writeAddingMultiplied( sampleFrame * src, f_cnt_t offset, f_cnt_t length, float level );

/** \brief Mixes a buffer of sampleframes additively to the ringbuffer at specified position, with
 * 	a specified multiplier applied to the frames
 * 	\param	src Pointer to the source buffer
 * 	\param offset Offset in milliseconds against current position, may *NOT* be negative
 * 	\param length Length of the source buffer, if zero, period size is used
 * 	\param level Multiplier applied to the frames before they're written to the ringbuffer
 */
	void writeAddingMultiplied( sampleFrame * src, float offset, f_cnt_t length, float level );

/** \brief Mixes a buffer of sampleframes additively to the ringbuffer at specified position, with
 * 	a specified multiplier applied to the frames, with swapped channels
 * 	\param	src Pointer to the source buffer
 * 	\param offset Offset in frames against current position, may *NOT* be negative
 * 	\param length Length of the source buffer, if zero, period size is used - must not be higher than the size of the ringbuffer!
 * 	\param level Multiplier applied to the frames before they're written to the ringbuffer
 */
	void writeSwappedAddingMultiplied( sampleFrame * src, f_cnt_t offset, f_cnt_t length, float level );

/** \brief Mixes a buffer of sampleframes additively to the ringbuffer at specified position, with
 * 	a specified multiplier applied to the frames, with swapped channels
 * 	\param	src Pointer to the source buffer
 * 	\param offset Offset in milliseconds against current position, may *NOT* be negative
 * 	\param length Length of the source buffer, if zero, period size is used
 * 	\param level Multiplier applied to the frames before they're written to the ringbuffer
 */
	void writeSwappedAddingMultiplied( sampleFrame * src, float offset, f_cnt_t length, float level );

protected slots:
	void updateSamplerate();

private:
	inline f_cnt_t msToFrames( float ms )
	{
		return static_cast<f_cnt_t>( ceilf( ms * (float)m_samplerate * 0.001f ) );
	}

	const fpp_t m_fpp;
	sample_rate_t m_samplerate;
	size_t m_size;
	sampleFrame * m_buffer;
	volatile unsigned int m_position;

};
#endif


code:
/*
 * RmsHelper.h - helper class for calculating RMS
 *
 * Copyright (c) 2014 Vesa Kivimäki <contact/dot/diizy/at/nbl/dot/fi>
 * Copyright (c) 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 RMS_HELPER_H
#define RMS_HELPER_H

#include "lmms_math.h"

class RmsHelper
{
public:
	RmsHelper( int size ) :
		m_buffer( NULL )
	{
		setSize( size );
	}
	virtual ~RmsHelper()
	{
		if( m_buffer ) delete[] m_buffer;
	}

	inline void setSize( int size )
	{
		if( m_buffer )
		{
			if( m_size < size )
			{
				delete m_buffer;
				m_buffer = new float[ size ];
				m_size = size;
				reset();
			}
			else
			{
				m_size = size;
				reset();
			}
		}
		else
		{
			m_buffer = new float[ size ];
			m_size = size;
			reset();
		}
	}

	inline void reset()
	{
		m_sizef = 1.0f / (float) m_size;
		m_pos = 0;
		m_sum = 0.0f;
		memset( m_buffer, 0, m_size * sizeof( float ) );
	}

	inline float update( const float in )
	{
		m_sum -= m_buffer[ m_pos ];
		m_sum += m_buffer[ m_pos ] = in * in;
		++m_pos %= m_size;
		return sqrtf( m_sum * m_sizef );
	}

private:
	float * m_buffer;
	float m_sum;
	unsigned int m_pos;
	unsigned int m_size;
	float m_sizef;
};

#endif


code:
/*
 * RowTableView.h - table with rows that act like single cells
 *
 * Copyright (c) 2016 Javier Serrano Polo <javier@jasp.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 ROW_TABLE_VIEW_H
#define ROW_TABLE_VIEW_H

#include <QTableView>

class RowDelegate;

class RowTableView : public QTableView
{
	Q_OBJECT
public:
	RowTableView( QWidget * parent = 0 );
	virtual ~RowTableView();

	void setModel( QAbstractItemModel * model ) override;

protected:
	void keyPressEvent( QKeyEvent * event ) override;

private:
	RowDelegate * m_rowDelegate;

} ;

#endif


code:
/*
 * Rubberband.h - rubberband - either own implementation for Qt3 or wrapper for
 *                             Qt4
 *
 * Copyright (c) 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 RUBBERBAND_H
#define RUBBERBAND_H

#include <QRubberBand>
#include <QtCore/QVector>

class selectableObject : public QWidget
{
	Q_OBJECT
public:
	selectableObject( QWidget * _parent ) :
		QWidget( _parent ),
		m_selected( false )
	{
	}

	virtual ~selectableObject()
	{
	}

	inline void setSelected( bool _selected )
	{
		m_selected = _selected;
		update();
	}

	inline bool isSelected() const
	{
		return( m_selected );
	}

public slots:
	virtual void update()
	{
		QWidget::update();
	}

private:
	bool m_selected;

} ;

class RubberBand : public QRubberBand
{
public:
	RubberBand( QWidget * _parent );
	virtual ~RubberBand();

	QVector<selectableObject *> selectedObjects() const;
	QVector<selectableObject *> selectableObjects() const;

protected:
	void resizeEvent( QResizeEvent * _re ) override;

private:

};

#endif


code:
/*
 * SampleBuffer.h - container-class SampleBuffer
 *
 * Copyright (c) 2005-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 SAMPLE_BUFFER_H
#define SAMPLE_BUFFER_H

#include <QtCore/QReadWriteLock>
#include <QtCore/QObject>

#include <samplerate.h>

#include "lmms_export.h"
#include "interpolation.h"
#include "lmms_basics.h"
#include "lmms_math.h"
#include "shared_object.h"
#include "MemoryManager.h"

class QPainter;
class QRect;

// values for buffer margins, used for various libsamplerate interpolation modes
// the array positions correspond to the converter_type parameter values in libsamplerate
// if there appears problems with playback on some interpolation mode, then the value for that mode
// may need to be higher - conversely, to optimize, some may work with lower values
const f_cnt_t MARGIN[] = { 64, 64, 64, 4, 4 };

class LMMS_EXPORT SampleBuffer : public QObject, public sharedObject
{
	Q_OBJECT
	MM_OPERATORS
public:
	enum LoopMode {
		LoopOff = 0,
		LoopOn,
		LoopPingPong
	};
	class LMMS_EXPORT handleState
	{
		MM_OPERATORS
	public:
		handleState(bool varyingPitch = false, int interpolationMode = SRC_LINEAR);
		virtual ~handleState();

		const f_cnt_t frameIndex() const
		{
			return m_frameIndex;
		}

		void setFrameIndex(f_cnt_t index)
		{
			m_frameIndex = index;
		}

		bool isBackwards() const
		{
			return m_isBackwards;
		}

		void setBackwards(bool backwards)
		{
			m_isBackwards = backwards;
		}

		int interpolationMode() const
		{
			return m_interpolationMode;
		}

	private:
		f_cnt_t m_frameIndex;
		const bool m_varyingPitch;
		bool m_isBackwards;
		SRC_STATE * m_resamplingData;
		int m_interpolationMode;

		friend class SampleBuffer;

	} ;

	SampleBuffer();
	// constructor which either loads sample _audio_file or decodes
	// base64-data out of string
	SampleBuffer(const QString & audioFile, bool isBase64Data = false);
	SampleBuffer(const sampleFrame * data, const f_cnt_t frames);
	explicit SampleBuffer(const f_cnt_t frames);
	SampleBuffer(const SampleBuffer & orig);

	friend void swap(SampleBuffer & first, SampleBuffer & second) noexcept;
	SampleBuffer& operator= (const SampleBuffer that);

	virtual ~SampleBuffer();

	bool play(
		sampleFrame * ab,
		handleState * state,
		const fpp_t frames,
		const float freq,
		const LoopMode loopMode = LoopOff
	);

	void visualize(
		QPainter & p,
		const QRect & dr,
		const QRect & clip,
		f_cnt_t fromFrame = 0,
		f_cnt_t toFrame = 0
	);
	inline void visualize(
		QPainter & p,
		const QRect & dr,
		f_cnt_t fromFrame = 0,
		f_cnt_t toFrame = 0
	)
	{
		visualize(p, dr, dr, fromFrame, toFrame);
	}

	inline const QString & audioFile() const
	{
		return m_audioFile;
	}

	inline f_cnt_t startFrame() const
	{
		return m_startFrame;
	}

	inline f_cnt_t endFrame() const
	{
		return m_endFrame;
	}

	inline f_cnt_t loopStartFrame() const
	{
		return m_loopStartFrame;
	}

	inline f_cnt_t loopEndFrame() const
	{
		return m_loopEndFrame;
	}

	void setLoopStartFrame(f_cnt_t start)
	{
		m_loopStartFrame = start;
	}

	void setLoopEndFrame(f_cnt_t end)
	{
		m_loopEndFrame = end;
	}

	void setAllPointFrames(
		f_cnt_t start,
		f_cnt_t end,
		f_cnt_t loopStart,
		f_cnt_t loopEnd
	)
	{
		m_startFrame = start;
		m_endFrame = end;
		m_loopStartFrame = loopStart;
		m_loopEndFrame = loopEnd;
	}

	inline f_cnt_t frames() const
	{
		return m_frames;
	}

	inline float amplification() const
	{
		return m_amplification;
	}

	inline bool reversed() const
	{
		return m_reversed;
	}

	inline float frequency() const
	{
		return m_frequency;
	}

	sample_rate_t sampleRate() const
	{
		return m_sampleRate;
	}

	int sampleLength() const
	{
		return double(m_endFrame - m_startFrame) / m_sampleRate * 1000;
	}

	inline void setFrequency(float freq)
	{
		m_frequency = freq;
	}

	inline void setSampleRate(sample_rate_t rate)
	{
		m_sampleRate = rate;
	}

	inline const sampleFrame * data() const
	{
		return m_data;
	}

	QString openAudioFile() const;
	QString openAndSetAudioFile();
	QString openAndSetWaveformFile();

	QString & toBase64(QString & dst) const;

	// protect calls from the GUI to this function with dataReadLock() and
	// dataUnlock()
	SampleBuffer * resample(const sample_rate_t srcSR, const sample_rate_t dstSR);

	void normalizeSampleRate(const sample_rate_t srcSR, bool keepSettings = false);

	// protect calls from the GUI to this function with dataReadLock() and
	// dataUnlock(), out of loops for efficiency
	inline sample_t userWaveSample(const float sample) const
	{
		f_cnt_t frames = m_frames;
		sampleFrame * data = m_data;
		const float frame = sample * frames;
		f_cnt_t f1 = static_cast<f_cnt_t>(frame) % frames;
		if (f1 < 0)
		{
			f1 += frames;
		}
		return linearInterpolate(data[f1][0], data[(f1 + 1) % frames][0], fraction(frame));
	}

	void dataReadLock()
	{
		m_varLock.lockForRead();
	}

	void dataUnlock()
	{
		m_varLock.unlock();
	}

public slots:
	void setAudioFile(const QString & audioFile);
	void loadFromBase64(const QString & data);
	void setStartFrame(const f_cnt_t s);
	void setEndFrame(const f_cnt_t e);
	void setAmplification(float a);
	void setReversed(bool on);
	void sampleRateChanged();

private:
	static sample_rate_t mixerSampleRate();

	void update(bool keepSettings = false);

	void convertIntToFloat(int_sample_t * & ibuf, f_cnt_t frames, int channels);
	void directFloatWrite(sample_t * & fbuf, f_cnt_t frames, int channels);

	f_cnt_t decodeSampleSF(
		QString fileName,
		sample_t * & buf,
		ch_cnt_t & channels,
		sample_rate_t & samplerate
	);
#ifdef LMMS_HAVE_OGGVORBIS
	f_cnt_t decodeSampleOGGVorbis(
		QString fileName,
		int_sample_t * & buf,
		ch_cnt_t & channels,
		sample_rate_t & samplerate
	);
#endif
	f_cnt_t decodeSampleDS(
		QString fileName,
		int_sample_t * & buf,
		ch_cnt_t & channels,
		sample_rate_t & samplerate
	);

	QString m_audioFile;
	sampleFrame * m_origData;
	f_cnt_t m_origFrames;
	sampleFrame * m_data;
	mutable QReadWriteLock m_varLock;
	f_cnt_t m_frames;
	f_cnt_t m_startFrame;
	f_cnt_t m_endFrame;
	f_cnt_t m_loopStartFrame;
	f_cnt_t m_loopEndFrame;
	float m_amplification;
	bool m_reversed;
	float m_frequency;
	sample_rate_t m_sampleRate;

	sampleFrame * getSampleFragment(
		f_cnt_t index,
		f_cnt_t frames,
		LoopMode loopMode,
		sampleFrame * * tmp,
		bool * backwards,
		f_cnt_t loopStart,
		f_cnt_t loopEnd,
		f_cnt_t end
	) const;

	f_cnt_t getLoopedIndex(f_cnt_t index, f_cnt_t startf, f_cnt_t endf) const;
	f_cnt_t getPingPongIndex(f_cnt_t index, f_cnt_t startf, f_cnt_t endf) const;

signals:
	void sampleUpdated();

} ;

#endif


code:
/*
 * SamplePlayHandle.h - play-handle for playing a sample
 *
 * Copyright (c) 2005-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 SAMPLE_PLAY_HANDLE_H
#define SAMPLE_PLAY_HANDLE_H

#include "SampleBuffer.h"
#include "AutomatableModel.h"
#include "PlayHandle.h"

class BBTrack;
class SampleTCO;
class Track;
class AudioPort;

class SamplePlayHandle : public PlayHandle
{
public:
	SamplePlayHandle( SampleBuffer* sampleBuffer , bool ownAudioPort = true );
	SamplePlayHandle( const QString& sampleFile );
	SamplePlayHandle( SampleTCO* tco );
	virtual ~SamplePlayHandle();

	inline bool affinityMatters() const override
	{
		return true;
	}

	void play( sampleFrame * buffer ) override;
	bool isFinished() const override;

	bool isFromTrack( const Track * _track ) const override;

	f_cnt_t totalFrames() const;
	inline f_cnt_t framesDone() const
	{
		return( m_frame );
	}
	void setDoneMayReturnTrue( bool _enable )
	{
		m_doneMayReturnTrue = _enable;
	}

	void setBBTrack( BBTrack * _bb_track )
	{
		m_bbTrack = _bb_track;
	}

	void setVolumeModel( FloatModel * _model )
	{
		m_volumeModel = _model;
	}

private:
	SampleBuffer * m_sampleBuffer;
	bool m_doneMayReturnTrue;

	f_cnt_t m_frame;
	SampleBuffer::handleState m_state;

	const bool m_ownAudioPort;

	FloatModel m_defaultVolumeModel;
	FloatModel * m_volumeModel;
	Track * m_track;

	BBTrack * m_bbTrack;

} ;

#endif


code:
/*
 * SampleRecordHandle.h - play-handle for recording a sample
 *
 * Copyright (c) 2008 Csaba Hruska <csaba.hruska/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 SAMPLE_RECORD_HANDLE_H
#define SAMPLE_RECORD_HANDLE_H

#include <QtCore/QList>
#include <QtCore/QPair>

#include "PlayHandle.h"
#include "TimePos.h"

class BBTrack;
class SampleBuffer;
class SampleTCO;
class Track;

class SampleRecordHandle : public PlayHandle
{
public:
	SampleRecordHandle( SampleTCO* tco );
	virtual ~SampleRecordHandle();

	void play( sampleFrame * _working_buffer ) override;
	bool isFinished() const override;

	bool isFromTrack( const Track * _track ) const override;

	f_cnt_t framesRecorded() const;
	void createSampleBuffer( SampleBuffer * * _sample_buf );

private:
	virtual void writeBuffer( const sampleFrame * _ab,
						const f_cnt_t _frames );

	typedef QList<QPair<sampleFrame *, f_cnt_t> > bufferList;
	bufferList m_buffers;
	f_cnt_t m_framesRecorded;
	TimePos m_minLength;

	Track * m_track;
	BBTrack * m_bbTrack;
	SampleTCO * m_tco;

} ;

#endif


code:
/*
 * SampleTrack.h - class SampleTrack, a track which provides arrangement of samples
 *
 * Copyright (c) 2005-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 SAMPLE_TRACK_H
#define SAMPLE_TRACK_H

#include <QDialog>
#include <QLayout>

#include "AudioPort.h"
#include "FadeButton.h"
#include "FxMixer.h"
#include "FxLineLcdSpinBox.h"
#include "Track.h"
#include "TrackContentObjectView.h"
#include "TrackView.h"

class EffectRackView;
class Knob;
class SampleBuffer;
class SampleTrackWindow;
class TrackLabelButton;
class QLineEdit;

class SampleTCO : public TrackContentObject
{
	Q_OBJECT
	mapPropertyFromModel(bool,isRecord,setRecord,m_recordModel);
public:
	SampleTCO( Track * _track );
	SampleTCO( const SampleTCO& orig );
	virtual ~SampleTCO();

	SampleTCO& operator=( const SampleTCO& that ) = delete;

	void changeLength( const TimePos & _length ) override;
	const QString & sampleFile() const;

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

	SampleBuffer* sampleBuffer()
	{
		return m_sampleBuffer;
	}

	TimePos sampleLength() const;
	void setSampleStartFrame( f_cnt_t startFrame );
	void setSamplePlayLength( f_cnt_t length );
	TrackContentObjectView * createView( TrackView * _tv ) override;

	bool isPlaying() const;
	void setIsPlaying(bool isPlaying);

public slots:
	void setSampleBuffer( SampleBuffer* sb );
	void setSampleFile( const QString & _sf );
	void updateLength();
	void toggleRecord();
	void playbackPositionChanged();
	void updateTrackTcos();

private:
	SampleBuffer* m_sampleBuffer;
	BoolModel m_recordModel;
	bool m_isPlaying;

	friend class SampleTCOView;

signals:
	void sampleChanged();
	void wasReversed();

} ;

class SampleTCOView : public TrackContentObjectView
{
	Q_OBJECT

public:
	SampleTCOView( SampleTCO * _tco, TrackView * _tv );
	virtual ~SampleTCOView() = default;

public slots:
	void updateSample();
	void reverseSample();

protected:
	void contextMenuEvent( QContextMenuEvent * _cme ) override;
	void mousePressEvent( QMouseEvent * _me ) override;
	void mouseReleaseEvent( QMouseEvent * _me ) override;
	void dragEnterEvent( QDragEnterEvent * _dee ) override;
	void dropEvent( QDropEvent * _de ) override;
	void mouseDoubleClickEvent( QMouseEvent * ) override;
	void paintEvent( QPaintEvent * ) override;

private:
	SampleTCO * m_tco;
	QPixmap m_paintPixmap;
} ;

class SampleTrack : public Track
{
	Q_OBJECT
public:
	SampleTrack( TrackContainer* tc );
	virtual ~SampleTrack();

	virtual bool play( const TimePos & _start, const fpp_t _frames,
						const f_cnt_t _frame_base, int _tco_num = -1 ) override;
	TrackView * createView( TrackContainerView* tcv ) override;
	TrackContentObject* createTCO(const TimePos & pos) override;

	virtual void saveTrackSpecificSettings( QDomDocument & _doc,
							QDomElement & _parent ) override;
	void loadTrackSpecificSettings( const QDomElement & _this ) override;

	inline IntModel * effectChannelModel()
	{
		return &m_effectChannelModel;
	}

	inline AudioPort * audioPort()
	{
		return &m_audioPort;
	}

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

	bool isPlaying()
	{
		return m_isPlaying;
	}

	void setPlaying(bool playing)
	{
		if (m_isPlaying != playing) { emit playingChanged(); }
		m_isPlaying = playing;
	}

signals:
	void playingChanged();

public slots:
	void updateTcos();
	void setPlayingTcos( bool isPlaying );
	void updateEffectChannel();

private:
	FloatModel m_volumeModel;
	FloatModel m_panningModel;
	IntModel m_effectChannelModel;
	AudioPort m_audioPort;
	bool m_isPlaying;

	friend class SampleTrackView;
	friend class SampleTrackWindow;

} ;

class SampleTrackView : public TrackView
{
	Q_OBJECT
public:
	SampleTrackView( SampleTrack* Track, TrackContainerView* tcv );
	virtual ~SampleTrackView();

	SampleTrackWindow * getSampleTrackWindow()
	{
		return m_window;
	}

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

	const SampleTrack * model() const
	{
		return castModel<SampleTrack>();
	}

	QMenu * createFxMenu( QString title, QString newFxLabel ) override;

public slots:
	void showEffects();
	void updateIndicator();

protected:
	void modelChanged() override;
	QString nodeName() const override
	{
		return "SampleTrackView";
	}

	void dragEnterEvent(QDragEnterEvent *dee) override;
	void dropEvent(QDropEvent *de) override;

private slots:
	void assignFxLine( int channelIndex );
	void createFxLine();

private:
	SampleTrackWindow * m_window;
	Knob * m_volumeKnob;
	Knob * m_panningKnob;
	FadeButton * m_activityIndicator;

	TrackLabelButton * m_tlb;

	FadeButton * getActivityIndicator() override
	{
		return m_activityIndicator;
	}

	friend class SampleTrackWindow;

} ;

class SampleTrackWindow : public QWidget, public ModelView, public SerializingObjectHook
{
	Q_OBJECT
public:
	SampleTrackWindow(SampleTrackView * tv);
	virtual ~SampleTrackWindow();

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

	const SampleTrack * model() const
	{
		return castModel<SampleTrack>();
	}

	void setSampleTrackView(SampleTrackView * tv);

	SampleTrackView *sampleTrackView()
	{
		return m_stv;
	}

public slots:
	void textChanged(const QString & new_name);
	void toggleVisibility(bool on);
	void updateName();

protected:
	// capture close-events for toggling sample-track-button
	void closeEvent(QCloseEvent * ce) override;

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

private:
	void modelChanged() override;

	SampleTrack * m_track;
	SampleTrackView * m_stv;

	// widgets on the top of an sample-track-window
	QLineEdit * m_nameLineEdit;
	Knob * m_volumeKnob;
	Knob * m_panningKnob;
	FxLineLcdSpinBox * m_effectChannelNumber;

	EffectRackView * m_effectRack;

} ;

#endif


code:
#ifndef SENDBUTTONINDICATOR_H
#define SENDBUTTONINDICATOR_H

#include <QDebug>
#include <QLabel>
#include <QPixmap>

#include "FxLine.h"
#include "FxMixerView.h"

class FxLine;
class FxMixerView;

class SendButtonIndicator : public QLabel
{
public:
	SendButtonIndicator( QWidget * _parent, FxLine * _owner,
						 FxMixerView * _mv);

	void mousePressEvent( QMouseEvent * e ) override;
	void updateLightStatus();

private:

	FxLine * m_parent;
	FxMixerView * m_mv;
	static QPixmap * s_qpmOn;
	static QPixmap * s_qpmOff;

	FloatModel * getSendModel();
};

#endif // SENDBUTTONINDICATOR_H


code:
/*
 * SerializingObject.h - declaration of class SerializingObject
 *
 * 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 SERIALIZING_OBJECT_H
#define SERIALIZING_OBJECT_H

#include <QtCore/QString>

#include "lmms_export.h"

class QDomDocument;
class QDomElement;

class SerializingObjectHook;

class LMMS_EXPORT SerializingObject
{
public:
	SerializingObject();
	virtual ~SerializingObject();

	virtual QDomElement saveState( QDomDocument & _doc, QDomElement & _parent );

	virtual void restoreState( const QDomElement & _this );

	// to be implemented by actual object
	virtual QString nodeName() const = 0;

	void setHook( SerializingObjectHook * _hook );

	SerializingObjectHook* hook()
	{
		return m_hook;
	}

protected:
	// to be implemented by sub-objects
	virtual void saveSettings( QDomDocument& doc, QDomElement& element ) = 0;
	virtual void loadSettings( const QDomElement& element ) = 0;

private:
	SerializingObjectHook * m_hook;

} ;

class SerializingObjectHook
{
public:
	SerializingObjectHook() :
		m_hookedIn( NULL )
	{
	}
	virtual ~SerializingObjectHook()
	{
		if( m_hookedIn != NULL )
		{
			m_hookedIn->setHook( NULL );
		}
	}

	virtual void saveSettings( QDomDocument & _doc, QDomElement & _this ) = 0;
	virtual void loadSettings( const QDomElement & _this ) = 0;

private:
	SerializingObject * m_hookedIn;

	friend class SerializingObject;

} ;

#endif


code:
/*
 * SetupDialog.h - dialog for setting up LMMS
 *
 * Copyright (c) 2005-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 SETUP_DIALOG_H
#define SETUP_DIALOG_H

#include <QDialog>
#include <QtCore/QMap>

#include "AudioDevice.h"
#include "AudioDeviceSetupWidget.h"
#include "LedCheckbox.h"
#include "lmmsconfig.h"
#include "MidiClient.h"
#include "MidiSetupWidget.h"

class QComboBox;
class QLabel;
class QLineEdit;
class QSlider;

class TabBar;

class SetupDialog : public QDialog
{
	Q_OBJECT

public:
	enum ConfigTabs
	{
		GeneralSettings,
		PerformanceSettings,
		AudioSettings,
		MidiSettings,
		PathsSettings
	};

	SetupDialog(ConfigTabs tab_to_open = GeneralSettings);
	virtual ~SetupDialog();

protected slots:
	void accept() override;

private slots:
	// General settings widget.
	void toggleDisplaydBFS(bool enabled);
	void toggleTooltips(bool enabled);
	void toggleDisplayWaveform(bool enabled);
	void toggleNoteLabels(bool enabled);
	void toggleCompactTrackButtons(bool enabled);
	void toggleOneInstrumentTrackWindow(bool enabled);
	void toggleSideBarOnRight(bool enabled);
	void toggleLetPreviewsFinish(bool enabled);
	void toggleSoloLegacyBehavior(bool enabled);
	void toggleMMPZ(bool enabled);
	void toggleDisableBackup(bool enabled);
	void toggleOpenLastProject(bool enabled);
	void setLanguage(int lang);

	// Performance settings widget.
	void setAutoSaveInterval(int time);
	void resetAutoSave();
	void toggleAutoSave(bool enabled);
	void toggleRunningAutoSave(bool enabled);
	void toggleSmoothScroll(bool enabled);
	void toggleAnimateAFP(bool enabled);
	void toggleSyncVSTPlugins(bool enabled);
	void vstEmbedMethodChanged();
	void toggleVSTAlwaysOnTop(bool en);
	void toggleDisableAutoQuit(bool enabled);

	// Audio settings widget.
	void audioInterfaceChanged(const QString & driver);
	void toggleHQAudioDev(bool enabled);
	void setBufferSize(int value);
	void resetBufferSize();

	// MIDI settings widget.
	void midiInterfaceChanged(const QString & driver);

	// Paths settings widget.
	void openWorkingDir();
	void setWorkingDir(const QString & workingDir);
	void openVSTDir();
	void setVSTDir(const QString & vstDir);
	void openLADSPADir();
	void setLADSPADir(const QString & ladspaDir);
	void openSF2Dir();
	void setSF2Dir(const QString & sf2Dir);
	void openSF2File();
	void setSF2File(const QString & sf2File);
	void openGIGDir();
	void setGIGDir(const QString & gigDir);
	void openThemeDir();
	void setThemeDir(const QString & themeDir);
	void openBackgroundPicFile();
	void setBackgroundPicFile(const QString & backgroundPicFile);

	void showRestartWarning();

private:
	TabBar * m_tabBar;

	// General settings widgets.
	bool m_displaydBFS;
	bool m_tooltips;
	bool m_displayWaveform;
	bool m_printNoteLabels;
	bool m_compactTrackButtons;
	bool m_oneInstrumentTrackWindow;
	bool m_sideBarOnRight;
	bool m_letPreviewsFinish;
	bool m_soloLegacyBehavior;
	bool m_MMPZ;
	bool m_disableBackup;
	bool m_openLastProject;
	QString m_lang;
	QStringList m_languages;

	// Performance settings widgets.
	int m_saveInterval;
	bool m_enableAutoSave;
	bool m_enableRunningAutoSave;
	QSlider * m_saveIntervalSlider;
	QLabel * m_saveIntervalLbl;
	LedCheckBox * m_autoSave;
	LedCheckBox * m_runningAutoSave;
	bool m_smoothScroll;
	bool m_animateAFP;
	QLabel * m_vstEmbedLbl;
	QComboBox* m_vstEmbedComboBox;
	QString m_vstEmbedMethod;
	LedCheckBox * m_vstAlwaysOnTopCheckBox;
	bool m_vstAlwaysOnTop;
	bool m_syncVSTPlugins;
	bool m_disableAutoQuit;

	typedef QMap<QString, AudioDeviceSetupWidget *> AswMap;
	typedef QMap<QString, MidiSetupWidget *> MswMap;
	typedef QMap<QString, QString> trMap;

	// Audio settings widgets.
	QComboBox * m_audioInterfaces;
	AswMap m_audioIfaceSetupWidgets;
	trMap m_audioIfaceNames;
	bool m_NaNHandler;
	bool m_hqAudioDev;
	int m_bufferSize;
	QSlider * m_bufferSizeSlider;
	QLabel * m_bufferSizeLbl;

	// MIDI settings widgets.
	QComboBox * m_midiInterfaces;
	MswMap m_midiIfaceSetupWidgets;
	trMap m_midiIfaceNames;
	QComboBox * m_assignableMidiDevices;

	// Paths settings widgets.
	QString m_workingDir;
	QString m_vstDir;
	QString m_ladspaDir;
	QString m_gigDir;
	QString m_sf2Dir;
#ifdef LMMS_HAVE_FLUIDSYNTH
	QString m_sf2File;
#endif
	QString m_themeDir;
	QString m_backgroundPicFile;

	QLineEdit * m_workingDirLineEdit;
	QLineEdit * m_vstDirLineEdit;
	QLineEdit * m_themeDirLineEdit;
	QLineEdit * m_ladspaDirLineEdit;
	QLineEdit * m_gigDirLineEdit;
	QLineEdit * m_sf2DirLineEdit;
#ifdef LMMS_HAVE_FLUIDSYNTH
	QLineEdit * m_sf2FileLineEdit;
#endif
	QLineEdit * m_backgroundPicFileLineEdit;

	QLabel * restartWarningLbl;
};
#endif


code:
/*
 * SideBar.h - side-bar in LMMS' MainWindow
 *
 * 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 SIDE_BAR_H
#define SIDE_BAR_H

#include <QtCore/QMap>
#include <QButtonGroup>
#include <QToolBar>

class QToolButton;
class SideBarWidget;

class SideBar : public QToolBar
{
	Q_OBJECT
public:
	SideBar( Qt::Orientation _orientation, QWidget * _parent );
	virtual ~SideBar();

	void appendTab( SideBarWidget * _sbw );

private slots:
	void toggleButton( QAbstractButton * _btn );

private:
	QButtonGroup m_btnGroup;
	typedef QMap<QToolButton *, QWidget *> ButtonMap;
	ButtonMap m_widgets;

} ;

#endif


code:
/*
 * SideBarWidget.h - base-class for all side-bar-widgets
 *
 * 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 SIDE_BAR_WIDGET_H
#define SIDE_BAR_WIDGET_H

#include <QPixmap>
#include <QVBoxLayout>
#include <QWidget>
#include <QPushButton>

class SideBarWidget : public QWidget
{
	Q_OBJECT
public:
	SideBarWidget( const QString & _title, const QPixmap & _icon,
							QWidget * _parent );
	virtual ~SideBarWidget();

	inline const QPixmap & icon() const
	{
		return m_icon;
	}
	inline const QString & title() const
	{
		return m_title;
	}

signals:
	void closeButtonClicked();

protected:
	void paintEvent( QPaintEvent * _pe ) override;
	void resizeEvent( QResizeEvent * _re ) override;
	void contextMenuEvent( QContextMenuEvent * ) override
	{
	}

	QWidget * contentParent()
	{
		return m_contents;
	}

	void addContentWidget( QWidget * _w )
	{
		m_layout->addWidget( _w );
	}

	void addContentLayout( QLayout * _l )
	{
		m_layout->addLayout( _l );
	}

private:
	QWidget * m_contents;
	QVBoxLayout * m_layout;
	QString m_title;
	QPixmap m_icon;
	QPushButton * m_closeBtn;
	const QSize m_buttonSize;

} ;

#endif