Merge pull request #2289 from Wallacoloo/midi-guicore

Consolidate midi config widgets & move them out of the core
This commit is contained in:
Colin Wallace
2015-09-06 18:11:58 +00:00
19 changed files with 235 additions and 301 deletions

View File

@@ -224,10 +224,11 @@ public:
void addRecentlyOpenedProject( const QString & _file );
const QString & value( const QString & _class,
const QString & _attribute ) const;
void setValue( const QString & _class, const QString & _attribute,
const QString & _value );
const QString & value( const QString & cls,
const QString & attribute ) const;
void setValue( const QString & cls, const QString & attribute,
const QString & value );
void deleteValue( const QString & cls, const QString & attribute);
void loadConfigFile();
void saveConfigFile();
@@ -256,7 +257,7 @@ private:
ConfigManager( const ConfigManager & _c );
~ConfigManager();
void upgrade_1_1_90();
void upgrade();
const QString m_lmmsRcFile;

View File

@@ -51,23 +51,14 @@ public:
inline static QString name()
{
return QT_TRANSLATE_NOOP( "setupWidget",
return QT_TRANSLATE_NOOP( "MidiSetupWidget",
"ALSA Raw-MIDI (Advanced Linux Sound Architecture)" );
}
class setupWidget : public MidiClientRaw::setupWidget
inline static QString configSection()
{
public:
setupWidget( QWidget * _parent );
virtual ~setupWidget();
virtual void saveSettings();
private:
QLineEdit * m_device;
} ;
return "MidiAlsaRaw";
}
protected:

View File

@@ -54,11 +54,16 @@ public:
inline static QString name()
{
return QT_TRANSLATE_NOOP( "setupWidget",
return QT_TRANSLATE_NOOP( "MidiSetupWidget",
"ALSA-Sequencer (Advanced Linux Sound "
"Architecture)" );
}
inline static QString configSection()
{
return "Midialsaseq";
}
virtual void processOutEvent( const MidiEvent & _me,
@@ -107,20 +112,6 @@ public:
}
class setupWidget : public MidiClient::setupWidget
{
public:
setupWidget( QWidget * _parent );
virtual ~setupWidget();
virtual void saveSettings();
private:
QLineEdit * m_device;
} ;
private slots:
void changeQueueTempo( bpm_t _bpm );
void updatePortList();

View File

@@ -45,12 +45,18 @@ public:
MidiApple();
virtual ~MidiApple();
static QString probeDevice();
inline static QString probeDevice()
{
return QString::Null(); // no midi device name
}
inline static QString name()
{
return QT_TRANSLATE_NOOP( "setupWidget", "Apple MIDI" );
return QT_TRANSLATE_NOOP( "MidiSetupWidget", "Apple MIDI" );
}
inline static QString configSection()
{
return QString::Null(); // no configuration settings
}
virtual void processOutEvent( const MidiEvent & _me,
@@ -106,18 +112,6 @@ public:
}
class setupWidget : public MidiClient::setupWidget
{
public:
setupWidget( QWidget * _parent );
virtual ~setupWidget();
void saveSettings()
{
}
} ;
private:// slots:
void updateDeviceList();

View File

@@ -106,32 +106,6 @@ public:
// any other working
static MidiClient * openMidiClient();
class setupWidget : public TabWidget
{
public:
setupWidget( const QString & _caption, QWidget * _parent ) :
TabWidget( TabWidget::tr( "Settings for %1" ).arg(
tr( _caption.toLatin1() ) ).toUpper(),
_parent )
{
}
virtual ~setupWidget()
{
}
virtual void saveSettings() = 0;
virtual void show()
{
parentWidget()->show();
QWidget::show();
}
} ;
protected:
QVector<MidiPort *> m_midiPorts;

View File

@@ -40,34 +40,19 @@ public:
inline static QString name()
{
return( QT_TRANSLATE_NOOP( "setupWidget",
return( QT_TRANSLATE_NOOP( "MidiSetupWidget",
"Dummy (no MIDI support)" ) );
}
class setupWidget : public MidiClient::setupWidget
inline static QString probeDevice()
{
public:
setupWidget( QWidget * _parent ) :
MidiClientRaw::setupWidget( MidiDummy::name(), _parent )
{
}
return QString::Null(); // no midi device name
}
virtual ~setupWidget()
{
}
virtual void saveSettings()
{
}
virtual void show()
{
parentWidget()->hide();
QWidget::show();
}
} ;
inline static QString configSection()
{
return QString::Null(); // no configuration settings
}
protected:

View File

@@ -49,24 +49,14 @@ public:
inline static QString name()
{
return( QT_TRANSLATE_NOOP( "setupWidget",
return( QT_TRANSLATE_NOOP( "MidiSetupWidget",
"OSS Raw-MIDI (Open Sound System)" ) );
}
class setupWidget : public MidiClientRaw::setupWidget
inline static QString configSection()
{
public:
setupWidget( QWidget * _parent );
virtual ~setupWidget();
virtual void saveSettings();
private:
QLineEdit * m_device;
} ;
return "midioss";
}
protected:
virtual void sendByte( const unsigned char c );

56
include/MidiSetupWidget.h Normal file
View File

@@ -0,0 +1,56 @@
/*
* MidiSetupWidget - class for configuring midi sources in the settings window
*
* Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of LMMS - http://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 MIDISETUPWIDGET_H
#define MIDISETUPWIDGET_H
#include <QLabel>
#include "TabWidget.h"
class QLineEdit;
class MidiSetupWidget : public TabWidget
{
MidiSetupWidget( const QString & caption, const QString & configSection,
const QString & devName, QWidget * parent );
public:
// create a widget with editors for all of @MidiClientType's fields
template <typename MidiClientType> static MidiSetupWidget* create( QWidget * parent )
{
QString configSection = MidiClientType::configSection();
QString dev = MidiClientType::probeDevice();
return new MidiSetupWidget(MidiClientType::name(), configSection, dev, parent);
}
void saveSettings();
void show();
private:
QString m_configSection;
QLineEdit *m_device;
};
#endif

View File

@@ -45,12 +45,20 @@ public:
MidiWinMM();
virtual ~MidiWinMM();
static QString probeDevice();
inline static QString probeDevice()
{
return QString::Null(); // no midi device name
}
inline static QString name()
{
return QT_TRANSLATE_NOOP( "setupWidget", "WinMM MIDI" );
return QT_TRANSLATE_NOOP( "MidiSetupWidget", "WinMM MIDI" );
}
inline static QString configSection()
{
return QString::Null(); // no configuration settings
}
@@ -104,19 +112,6 @@ public:
}
class setupWidget : public MidiClient::setupWidget
{
public:
setupWidget( QWidget * _parent );
virtual ~setupWidget();
virtual void saveSettings()
{
}
} ;
private:// slots:
void updateDeviceList();

View File

@@ -32,6 +32,7 @@
#include "lmmsconfig.h"
#include "AudioDevice.h"
#include "MidiClient.h"
#include "MidiSetupWidget.h"
#include "AudioDeviceSetupWidget.h"
@@ -181,7 +182,7 @@ private:
bool m_disableAutoQuit;
typedef QMap<QString, AudioDeviceSetupWidget *> AswMap;
typedef QMap<QString, MidiClient::setupWidget *> MswMap;
typedef QMap<QString, MidiSetupWidget *> MswMap;
typedef QMap<QString, QString> trMap;
QComboBox * m_audioInterfaces;

View File

@@ -104,6 +104,28 @@ ConfigManager::~ConfigManager()
}
void ConfigManager::upgrade_1_1_90()
{
// Remove trailing " (bad latency!)" string which was once saved with PulseAudio
if( value( "mixer", "audiodev" ).startsWith( "PulseAudio (" ) )
{
setValue("mixer", "audiodev", "PulseAudio");
}
// MidiAlsaRaw used to store the device info as "Device" instead of "device"
if ( value( "MidiAlsaRaw", "device" ).isNull() )
{
// copy "device" = "Device" and then delete the old "Device" (further down)
QString oldDevice = value( "MidiAlsaRaw", "Device" );
setValue("MidiAlsaRaw", "device", oldDevice);
}
if ( !value( "MidiAlsaRaw", "device" ).isNull() )
{
// delete the old "Device" in the case that we just copied it to "device"
// or if the user somehow set both the "Device" and "device" fields
deleteValue("MidiAlsaRaw", "Device");
}
}
void ConfigManager::upgrade()
@@ -116,13 +138,9 @@ void ConfigManager::upgrade()
ProjectVersion createdWith = m_version;
// Remove trailing " (bad latency!)" string which was once saved with PulseAudio
if ( createdWith.setCompareType(Build) < "1.1.90" )
{
if( value( "mixer", "audiodev" ).startsWith( "PulseAudio (" ) )
{
setValue("mixer", "audiodev", "PulseAudio");
}
upgrade_1_1_90();
}
// Don't use old themes as they break the UI (i.e. 0.4 != 1.0, etc)
@@ -252,16 +270,16 @@ void ConfigManager::addRecentlyOpenedProject( const QString & _file )
const QString & ConfigManager::value( const QString & _class,
const QString & _attribute ) const
const QString & ConfigManager::value( const QString & cls,
const QString & attribute ) const
{
if( m_settings.contains( _class ) )
if( m_settings.contains( cls ) )
{
for( stringPairVector::const_iterator it =
m_settings[_class].begin();
it != m_settings[_class].end(); ++it )
m_settings[cls].begin();
it != m_settings[cls].end(); ++it )
{
if( ( *it ).first == _attribute )
if( ( *it ).first == attribute )
{
return ( *it ).second ;
}
@@ -274,27 +292,43 @@ const QString & ConfigManager::value( const QString & _class,
void ConfigManager::setValue( const QString & _class,
const QString & _attribute,
const QString & _value )
void ConfigManager::setValue( const QString & cls,
const QString & attribute,
const QString & value )
{
if( m_settings.contains( _class ) )
if( m_settings.contains( cls ) )
{
for( stringPairVector::iterator it = m_settings[_class].begin();
it != m_settings[_class].end(); ++it )
for( stringPairVector::iterator it = m_settings[cls].begin();
it != m_settings[cls].end(); ++it )
{
if( ( *it ).first == _attribute )
if( ( *it ).first == attribute )
{
( *it ).second = _value;
( *it ).second = value;
return;
}
}
}
// not in map yet, so we have to add it...
m_settings[_class].push_back( qMakePair( _attribute, _value ) );
m_settings[cls].push_back( qMakePair( attribute, value ) );
}
void ConfigManager::deleteValue( const QString & cls, const QString & attribute)
{
if( m_settings.contains( cls ) )
{
for( stringPairVector::iterator it = m_settings[cls].begin();
it != m_settings[cls].end(); ++it )
{
if( ( *it ).first == attribute )
{
m_settings[cls].erase(it);
return;
}
}
}
}
void ConfigManager::loadConfigFile()
{

View File

@@ -22,9 +22,6 @@
*
*/
#include <QLabel>
#include <QLineEdit>
#include "MidiAlsaRaw.h"
#include "ConfigManager.h"
#include "gui_templates.h"
@@ -80,7 +77,7 @@ MidiAlsaRaw::~MidiAlsaRaw()
QString MidiAlsaRaw::probeDevice()
{
QString dev = ConfigManager::inst()->value( "MidiAlsaRaw", "Device" );
QString dev = ConfigManager::inst()->value( "MidiAlsaRaw", "device" );
if( dev == "" )
{
if( getenv( "MIDIDEV" ) != NULL )
@@ -173,36 +170,5 @@ void MidiAlsaRaw::run()
}
MidiAlsaRaw::setupWidget::setupWidget( QWidget * _parent ) :
MidiClientRaw::setupWidget( MidiAlsaRaw::name(), _parent )
{
m_device = new QLineEdit( MidiAlsaRaw::probeDevice(), this );
m_device->setGeometry( 10, 20, 160, 20 );
QLabel * dev_lbl = new QLabel( tr( "DEVICE" ), this );
dev_lbl->setFont( pointSize<7>( dev_lbl->font() ) );
dev_lbl->setGeometry( 10, 40, 160, 10 );
}
MidiAlsaRaw::setupWidget::~setupWidget()
{
}
void MidiAlsaRaw::setupWidget::saveSettings()
{
ConfigManager::inst()->setValue( "MidiAlsaRaw", "Device",
m_device->text() );
}
#endif

View File

@@ -22,9 +22,6 @@
*
*/
#include <QLabel>
#include <QLineEdit>
#include "MidiAlsaSeq.h"
#include "ConfigManager.h"
#include "Engine.h"
@@ -702,41 +699,5 @@ void MidiAlsaSeq::updatePortList()
}
MidiAlsaSeq::setupWidget::setupWidget( QWidget * _parent ) :
MidiClient::setupWidget( MidiAlsaSeq::name(), _parent )
{
m_device = new QLineEdit( MidiAlsaSeq::probeDevice(), this );
m_device->setGeometry( 10, 20, 160, 20 );
QLabel * dev_lbl = new QLabel( tr( "DEVICE" ), this );
dev_lbl->setFont( pointSize<7>( dev_lbl->font() ) );
dev_lbl->setGeometry( 10, 40, 160, 10 );
}
MidiAlsaSeq::setupWidget::~setupWidget()
{
}
void MidiAlsaSeq::setupWidget::saveSettings()
{
ConfigManager::inst()->setValue( "Midialsaseq", "device",
m_device->text() );
}
#endif

View File

@@ -26,8 +26,6 @@
#include "MidiApple.h"
#include <QLabel>
#include <QLineEdit>
#include <QtAlgorithms>
#include <algorithm>
@@ -624,20 +622,6 @@ char * MidiApple::getFullName(MIDIEndpointRef &endpoint_ref)
}
MidiApple::setupWidget::setupWidget( QWidget* parent ) :
MidiClient::setupWidget( MidiApple::name(), parent )
{
}
MidiApple::setupWidget::~setupWidget()
{
}
#endif

View File

@@ -28,9 +28,6 @@
#ifdef LMMS_HAVE_OSS
#include <QLabel>
#include <QLineEdit>
#ifdef LMMS_HAVE_STDLIB_H
#include <stdlib.h>
@@ -111,38 +108,6 @@ void MidiOss::run()
}
MidiOss::setupWidget::setupWidget( QWidget * _parent ) :
MidiClientRaw::setupWidget( MidiOss::name(), _parent )
{
m_device = new QLineEdit( MidiOss::probeDevice(), this );
m_device->setGeometry( 10, 20, 160, 20 );
QLabel * dev_lbl = new QLabel( tr( "DEVICE" ), this );
dev_lbl->setFont( pointSize<7>( dev_lbl->font() ) );
dev_lbl->setGeometry( 10, 40, 160, 10 );
}
MidiOss::setupWidget::~setupWidget()
{
}
void MidiOss::setupWidget::saveSettings()
{
ConfigManager::inst()->setValue( "midioss", "device",
m_device->text() );
}
#endif

View File

@@ -22,9 +22,6 @@
*
*/
#include <QLabel>
#include <QLineEdit>
#include "MidiWinMM.h"
#include "ConfigManager.h"
#include "Engine.h"
@@ -307,25 +304,5 @@ void MidiWinMM::openDevices()
}
MidiWinMM::setupWidget::setupWidget( QWidget* parent ) :
MidiClient::setupWidget( MidiWinMM::name(), parent )
{
}
MidiWinMM::setupWidget::~setupWidget()
{
}
#endif

View File

@@ -20,6 +20,7 @@ SET(LMMS_SRCS
gui/LmmsPalette.cpp
gui/LmmsStyle.cpp
gui/MainWindow.cpp
gui/MidiSetupWidget.cpp
gui/ModelView.cpp
gui/PeakControllerDialog.cpp
gui/PianoView.cpp

View File

@@ -0,0 +1,68 @@
/*
* MidiSetupWidget - class for configuring midi sources in the settings window
*
* Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* This file is part of LMMS - http://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.
*
*/
#include "MidiSetupWidget.h"
#include <QLineEdit>
#include "ConfigManager.h"
#include "gui_templates.h"
MidiSetupWidget::MidiSetupWidget( const QString & caption, const QString & configSection,
const QString & devName, QWidget * parent ) :
TabWidget( TabWidget::tr( "Settings for %1" ).arg(
tr( caption.toLatin1() ) ).toUpper(), parent ),
m_configSection(configSection),
m_device(nullptr)
{
// supply devName=QString::Null() (distinct from QString(""))
// to indicate that there is no editable DEVICE field
if (!devName.isNull())
{
m_device = new QLineEdit( devName, this );
m_device->setGeometry( 10, 20, 160, 20 );
QLabel * dev_lbl = new QLabel( tr( "DEVICE" ), this );
dev_lbl->setFont( pointSize<7>( dev_lbl->font() ) );
dev_lbl->setGeometry( 10, 40, 160, 10 );
}
}
void MidiSetupWidget::saveSettings()
{
if (!m_configSection.isEmpty() && m_device)
{
ConfigManager::inst()->setValue( m_configSection, "device",
m_device->text() );
}
}
void MidiSetupWidget::show()
{
// the setup widget should only be visible if the device has some configurable attributes
bool visible = !m_configSection.isEmpty();
parentWidget()->setVisible(visible);
QWidget::setVisible(visible);
}

View File

@@ -817,28 +817,28 @@ SetupDialog::SetupDialog( ConfigTabs _tab_to_open ) :
#ifdef LMMS_HAVE_ALSA
m_midiIfaceSetupWidgets[MidiAlsaSeq::name()] =
new MidiAlsaSeq::setupWidget( msw );
MidiSetupWidget::create<MidiAlsaSeq>( msw );
m_midiIfaceSetupWidgets[MidiAlsaRaw::name()] =
new MidiAlsaRaw::setupWidget( msw );
MidiSetupWidget::create<MidiAlsaRaw>( msw );
#endif
#ifdef LMMS_HAVE_OSS
m_midiIfaceSetupWidgets[MidiOss::name()] =
new MidiOss::setupWidget( msw );
MidiSetupWidget::create<MidiOss>( msw );
#endif
#ifdef LMMS_BUILD_WIN32
m_midiIfaceSetupWidgets[MidiWinMM::name()] =
new MidiWinMM::setupWidget( msw );
MidiSetupWidget::create<MidiWinMM>( msw );
#endif
#ifdef LMMS_BUILD_APPLE
m_midiIfaceSetupWidgets[MidiApple::name()] =
new MidiApple::setupWidget( msw );
MidiSetupWidget::create<MidiApple>( msw );
#endif
m_midiIfaceSetupWidgets[MidiDummy::name()] =
new MidiDummy::setupWidget( msw );
MidiSetupWidget::create<MidiDummy>( msw );
for( MswMap::iterator it = m_midiIfaceSetupWidgets.begin();