Skip to content

Commit

Permalink
fix #308469: changing portaudio preferences does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
SKefalidis committed Sep 1, 2020
1 parent f4c0004 commit a974a66
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
8 changes: 1 addition & 7 deletions mscore/preferenceslistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ IntPreferenceItem::IntPreferenceItem(QString name, QSpinBox* editor, std::functi

IntPreferenceItem::IntPreferenceItem(QString name, QComboBox* editor, std::function<void()> applyFunc, std::function<void()> updateFunc)
: PreferenceItem(name),
_initialValue(preferences.getInt(name)),
_editorComboBox(editor)
{
int index = _editorComboBox->findData(preferences.getInt(name));
Expand All @@ -255,7 +254,6 @@ void IntPreferenceItem::apply()
}
else if (_editorComboBox) {
int newValue = _editorComboBox->currentData().toInt();
_initialValue = newValue;
PreferenceItem::apply(newValue);
_initialEditorIndex = _editorComboBox->currentIndex();
}
Expand Down Expand Up @@ -363,7 +361,6 @@ DoublePreferenceItem::DoublePreferenceItem(QString name, QDoubleSpinBox* editor,

DoublePreferenceItem::DoublePreferenceItem(QString name, QComboBox* editor, std::function<void()> applyFunc, std::function<void()> updateFunc)
: PreferenceItem(name),
_initialValue(preferences.getDouble(name)),
_editorComboBox(editor)
{
int index = _editorComboBox->findData(preferences.getDouble(name));
Expand Down Expand Up @@ -401,14 +398,13 @@ void DoublePreferenceItem::apply()
}
else if (_editorComboBox) {
double newValue = _editorComboBox->currentData().toDouble();
_initialValue = newValue;
PreferenceItem::apply(newValue);
_initialEditorIndex = _editorComboBox->currentIndex();
}
else if (_editorSpinBox) {
double newValue = _editorSpinBox->value();
_initialValue = newValue;
PreferenceItem::apply(newValue);
_initialEditorIndex = _editorComboBox->currentIndex();
}
}
}
Expand Down Expand Up @@ -679,7 +675,6 @@ StringPreferenceItem::StringPreferenceItem(QString name, QFontComboBox* editor,

StringPreferenceItem::StringPreferenceItem(QString name, QComboBox* editor, std::function<void()> applyFunc, std::function<void()> updateFunc)
: PreferenceItem(name),
_initialValue(preferences.getString(name)),
_editorComboBox(editor)
{
int index = _editorComboBox->findData(preferences.getString(name));
Expand Down Expand Up @@ -723,7 +718,6 @@ void StringPreferenceItem::apply()
}
else if (_editorComboBox) {
QString newValue = _editorComboBox->currentText();
_initialValue = newValue;
PreferenceItem::apply(newValue);
_initialEditorIndex = _editorComboBox->currentIndex();;
}
Expand Down
4 changes: 2 additions & 2 deletions mscore/preferenceslistwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class PreferenceItem : public QObject, public QTreeWidgetItem {
// BoolPreferenceItem
//---------------------------------------------------------
class BoolPreferenceItem : public PreferenceItem {
bool _initialValue;
bool _initialValue { false };
QCheckBox* _editorCheckBox { nullptr };
QGroupBox* _editorGroupBox { nullptr };
QRadioButton* _editorRadioButton { nullptr };
Expand All @@ -85,7 +85,7 @@ class BoolPreferenceItem : public PreferenceItem {
// IntPreferenceItem
//---------------------------------------------------------
class IntPreferenceItem : public PreferenceItem {
int _initialValue;
int _initialValue { 0 };
int _initialEditorIndex { -1 };
QSpinBox* _editorSpinBox { nullptr };
QComboBox* _editorComboBox { nullptr };
Expand Down
45 changes: 22 additions & 23 deletions mscore/prefsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,6 @@ void PreferenceDialog::start()
new BoolPreferenceItem(PREF_SCORE_NOTE_WARNPITCHRANGE, warnPitchRange),
new StringPreferenceItem(PREF_IMPORT_OVERTURE_CHARSET, importCharsetListOve, nullptr, [&](){ updateCharsetListOve(); }), // keep the default apply
new StringPreferenceItem(PREF_IMPORT_GUITARPRO_CHARSET, importCharsetListGP, nullptr, [&](){ updateCharsetListGP(); }), // keep the default apply
#ifdef USE_PORTMIDI
new StringPreferenceItem(PREF_IO_PORTMIDI_INPUTDEVICE, portMidiInput),
new StringPreferenceItem(PREF_IO_PORTMIDI_OUTPUTDEVICE, portMidiOutput),
new IntPreferenceItem(PREF_IO_PORTMIDI_OUTPUTLATENCYMILLISECONDS, portMidiOutputLatencyMilliseconds),
#endif
new IntPreferenceItem(PREF_EXPORT_AUDIO_SAMPLERATE, exportAudioSampleRate),
new IntPreferenceItem(PREF_EXPORT_MP3_BITRATE, exportMp3BitRate),
new StringPreferenceItem(PREF_SCORE_STYLE_DEFAULTSTYLEFILE, defaultStyle,
Expand Down Expand Up @@ -512,6 +507,13 @@ void PreferenceDialog::start()
new IntPreferenceItem(PREF_IO_ALSA_SAMPLERATE, alsaSampleRate, doNothing),
new IntPreferenceItem(PREF_IO_ALSA_PERIODSIZE, alsaPeriodSize, doNothing),
new IntPreferenceItem(PREF_IO_ALSA_FRAGMENTS, alsaFragments, doNothing),
new IntPreferenceItem(PREF_IO_PORTAUDIO_DEVICE, portaudioApi, doNothing, doNothing),
new IntPreferenceItem(PREF_IO_PORTAUDIO_DEVICE, portaudioDevice, doNothing, doNothing),
#ifdef USE_PORTMIDI
new StringPreferenceItem(PREF_IO_PORTMIDI_INPUTDEVICE, portMidiInput, doNothing, doNothing),
new StringPreferenceItem(PREF_IO_PORTMIDI_OUTPUTDEVICE, portMidiOutput, doNothing, doNothing),
new IntPreferenceItem(PREF_IO_PORTMIDI_OUTPUTLATENCYMILLISECONDS, portMidiOutputLatencyMilliseconds),
#endif
};

// These connections are used to enable the Apply button and to save only the changed preferences.
Expand Down Expand Up @@ -700,8 +702,6 @@ void PreferenceDialog::updateValues(bool useDefaultValues, bool setup)
curMidiOutIdx = i + 1;
}
portMidiOutput->setCurrentIndex(curMidiOutIdx);

portMidiOutputLatencyMilliseconds->setValue(preferences.getInt(PREF_IO_PORTMIDI_OUTPUTLATENCYMILLISECONDS));
}
#endif
}
Expand Down Expand Up @@ -1375,26 +1375,25 @@ void PreferenceDialog::apply()

restartAudioEngine();
}
}

#ifdef USE_PORTAUDIO
if (portAudioIsUsed && !noSeq) {
Portaudio* audio = static_cast<Portaudio*>(seq->driver());
preferences.setPreference(PREF_IO_PORTAUDIO_DEVICE, audio->deviceIndex(portaudioApi->currentIndex(), portaudioDevice->currentIndex()));
}
#endif
#ifdef USE_PORTAUDIO
if (portAudioIsUsed && !noSeq) {
Portaudio* audio = static_cast<Portaudio*>(seq->driver());
preferences.setPreference(PREF_IO_PORTAUDIO_DEVICE, audio->deviceIndex(portaudioApi->currentIndex(), portaudioDevice->currentIndex()));
}
#endif

#ifdef USE_PORTMIDI
if (seq->driver() && static_cast<PortMidiDriver*>(static_cast<Portaudio*>(seq->driver())->mididriver())->isSameCoreMidiIacBus(preferences.getString(PREF_IO_PORTMIDI_INPUTDEVICE), preferences.getString(PREF_IO_PORTMIDI_OUTPUTDEVICE))) {
#ifdef USE_PORTMIDI
preferences.setPreference(PREF_IO_PORTMIDI_INPUTDEVICE, portMidiInput->currentText());
preferences.setPreference(PREF_IO_PORTMIDI_OUTPUTDEVICE, portMidiOutput->currentText());
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Possible MIDI Loopback"));
msgBox.setIcon(QMessageBox::Warning);
msgBox.setText(tr("Warning: You used the same CoreMIDI IAC bus for input and output. This will cause problematic loopback, whereby MuseScore's output MIDI messages will be sent back to MuseScore as input, causing confusion. To avoid this problem, access Audio MIDI Setup via Spotlight to create a dedicated virtual port for MuseScore's MIDI output, restart MuseScore, return to Preferences, and select your new virtual port for MuseScore's MIDI output. Other programs may then use that dedicated virtual port to receive MuseScore's MIDI output."));
msgBox.exec();
if (seq->driver() && static_cast<PortMidiDriver*>(static_cast<Portaudio*>(seq->driver())->mididriver())->isSameCoreMidiIacBus(preferences.getString(PREF_IO_PORTMIDI_INPUTDEVICE), preferences.getString(PREF_IO_PORTMIDI_OUTPUTDEVICE))) {
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Possible MIDI Loopback"));
msgBox.setIcon(QMessageBox::Warning);
msgBox.setText(tr("Warning: You used the same CoreMIDI IAC bus for input and output. This will cause problematic loopback, whereby MuseScore's output MIDI messages will be sent back to MuseScore as input, causing confusion. To avoid this problem, access Audio MIDI Setup via Spotlight to create a dedicated virtual port for MuseScore's MIDI output, restart MuseScore, return to Preferences, and select your new virtual port for MuseScore's MIDI output. Other programs may then use that dedicated virtual port to receive MuseScore's MIDI output."));
msgBox.exec();
}
#endif
}
#endif

if (shortcutsChanged) {
shortcutsChanged = false;
Expand Down

0 comments on commit a974a66

Please sign in to comment.