From 47f0726dd3029b2926d0de5fd5d01c68d9cc83ee Mon Sep 17 00:00:00 2001 From: Joachim Schmitz Date: Sun, 12 Feb 2017 20:34:16 +0100 Subject: [PATCH] fix #50926: add setting and option for MP3 bitrate --- mscore/exportmp3.cpp | 9 +- mscore/musescore.cpp | 10 ++ mscore/preferences.cpp | 78 ++++----- mscore/preferences.h | 1 + mscore/prefsdialog.ui | 363 ++++++++++++++++++++++++++++------------- 5 files changed, 303 insertions(+), 158 deletions(-) diff --git a/mscore/exportmp3.cpp b/mscore/exportmp3.cpp index b549be9b0b617..18f77fe9b00d8 100644 --- a/mscore/exportmp3.cpp +++ b/mscore/exportmp3.cpp @@ -655,6 +655,7 @@ bool MuseScore::saveMp3(Score* score, const QString& name) int oldSampleRate = MScore::sampleRate; int sampleRate = preferences.exportAudioSampleRate; + exporter.setBitrate(preferences.exportMp3BitRate); int inSamples = exporter.initializeStream(channels, sampleRate); if (inSamples < 0) { @@ -720,12 +721,12 @@ bool MuseScore::saveMp3(Score* score, const QString& name) // // init instruments // - foreach(Part* part, score->parts()) { + for (Part* part: score->parts()) { const InstrumentList* il = part->instruments(); - for(auto i = il->begin(); i!= il->end(); i++) { - foreach(const Channel* a, i->second->channel()) { + for (auto i = il->begin(); i!= il->end(); i++) { + for (const Channel* a: i->second->channel()) { a->updateInitList(); - foreach(MidiCoreEvent e, a->init) { + for (MidiCoreEvent e: a->init) { if (e.type() == ME_INVALID) continue; e.setChannel(a->channel); diff --git a/mscore/musescore.cpp b/mscore/musescore.cpp index 7943a3779e06e..267b048f77c36 100644 --- a/mscore/musescore.cpp +++ b/mscore/musescore.cpp @@ -5390,6 +5390,7 @@ int main(int argc, char* av[]) parser.addOption(QCommandLineOption({"P", "export-score-parts"}, "Used with -o .pdf, export score + parts")); parser.addOption(QCommandLineOption( "no-fallback-font", "will not use Bravura as fallback musical font")); parser.addOption(QCommandLineOption({"f", "force"}, "Used with -o, ignore warnings reg. score being corrupted or from wrong version")); + parser.addOption(QCommandLineOption({"b", "bitrate"}, "Used with -o .mp3, sets bitrate", "bitrate")); parser.addPositionalArgument("scorefiles", "The files to open", "[scorefile...]"); @@ -5501,6 +5502,15 @@ int main(int argc, char* av[]) if (exportScoreParts && !converterMode) parser.showHelp(EXIT_FAILURE); ignoreWarnings = parser.isSet("f"); + if (parser.isSet("b")) { + QString temp = parser.value("b"); + if (temp.isEmpty()) + parser.showHelp(EXIT_FAILURE); + bool ok = false; + preferences.exportMp3BitRate = temp.toInt(&ok); + if (!ok) + preferences.exportMp3BitRate = 128; + } QStringList argv = parser.positionalArguments(); diff --git a/mscore/preferences.cpp b/mscore/preferences.cpp index 8f624c09b9382..a05cbe82cfd4c 100644 --- a/mscore/preferences.cpp +++ b/mscore/preferences.cpp @@ -53,8 +53,6 @@ bool useALSA = false, useJACK = false, usePortaudio = false, usePulseAudio = fal extern bool externalStyle; -static int exportAudioSampleRates[2] = { 44100, 48000 }; - //--------------------------------------------------------- // Preferences //--------------------------------------------------------- @@ -201,7 +199,8 @@ void Preferences::init() #else nativeDialogs = false; // don't use system native file dialogs #endif - exportAudioSampleRate = exportAudioSampleRates[0]; + exportAudioSampleRate = 44100; + exportMp3BitRate = 128; workspace = "Basic"; exportPdfDpi = 300; @@ -240,7 +239,7 @@ void Preferences::write() s.setValue("showNavigator", showNavigator); s.setValue("showPlayPanel", showPlayPanel); s.setValue("showSplashScreen", showSplashScreen); - s.setValue("showStartcenter1", showStartcenter); + s.setValue("showStartcenter1", showStartcenter); s.setValue("showStatusBar", showStatusBar); @@ -258,7 +257,7 @@ void Preferences::write() s.setValue("alsaPeriodSize", alsaPeriodSize); s.setValue("alsaFragments", alsaFragments); s.setValue("portaudioDevice", portaudioDevice); - s.setValue("portMidiInput", portMidiInput); + s.setValue("portMidiInput", portMidiInput); s.setValue("layoutBreakColor", MScore::layoutBreakColor.name(QColor::NameFormat::HexArgb)); s.setValue("frameMarginColor", MScore::frameMarginColor.name(QColor::NameFormat::HexArgb)); @@ -282,7 +281,7 @@ void Preferences::write() s.setValue("musicxmlImportLayout", musicxmlImportLayout); s.setValue("musicxmlImportBreaks", musicxmlImportBreaks); s.setValue("musicxmlExportLayout", musicxmlExportLayout); - switch(musicxmlExportBreaks) { + switch (musicxmlExportBreaks) { case MusicxmlExportBreaks::ALL: s.setValue("musicxmlExportBreaks", "all"); break; case MusicxmlExportBreaks::MANUAL: s.setValue("musicxmlExportBreaks", "manual"); break; case MusicxmlExportBreaks::NO: s.setValue("musicxmlExportBreaks", "no"); break; @@ -337,6 +336,7 @@ void Preferences::write() s.setValue("vraster", MScore::vRaster()); s.setValue("nativeDialogs", nativeDialogs); s.setValue("exportAudioSampleRate", exportAudioSampleRate); + s.setValue("exportMp3BitRate", exportMp3BitRate); s.setValue("workspace", workspace); s.setValue("exportPdfDpi", exportPdfDpi); @@ -501,7 +501,7 @@ void Preferences::read() dir.mkpath(myImagesPath); dir.mkpath(myTemplatesPath); dir.mkpath(myPluginsPath); - foreach (QString path, mySoundfontsPath.split(";")) + for (QString path: mySoundfontsPath.split(";")) dir.mkpath(path); MScore::setHRaster(s.value("hraster", MScore::hRaster()).toInt()); @@ -509,6 +509,7 @@ void Preferences::read() nativeDialogs = s.value("nativeDialogs", nativeDialogs).toBool(); exportAudioSampleRate = s.value("exportAudioSampleRate", exportAudioSampleRate).toInt(); + exportMp3BitRate = s.value("exportMp3Bitrate", exportMp3BitRate).toInt(); workspace = s.value("workspace", workspace).toString(); exportPdfDpi = s.value("exportPdfDpi", exportPdfDpi).toInt(); @@ -664,11 +665,6 @@ PreferenceDialog::PreferenceDialog(QWidget* parent) recordButtons->addButton(recordEditMode, RMIDI_NOTE_EDIT_MODE); recordButtons->addButton(recordRealtimeAdvance, RMIDI_REALTIME_ADVANCE); - int n = sizeof(exportAudioSampleRates)/sizeof(*exportAudioSampleRates); - exportAudioSampleRate->clear(); - for (int idx = 0; idx < n; ++idx) - exportAudioSampleRate->addItem(QString("%1").arg(exportAudioSampleRates[idx])); - connect(recordButtons, SIGNAL(buttonClicked(int)), SLOT(recordButtonClicked(int))); connect(midiRemoteControlClear, SIGNAL(clicked()), SLOT(midiRemoteControlClearClicked())); connect(portaudioDriver, SIGNAL(toggled(bool)), SLOT(exclusiveAudioDriver(bool))); @@ -720,7 +716,7 @@ void PreferenceDialog::hideEvent(QHideEvent* ev) void PreferenceDialog::recordButtonClicked(int val) { - foreach(QAbstractButton* b, recordButtons->buttons()) { + for (QAbstractButton* b: recordButtons->buttons()) { b->setChecked(recordButtons->id(b) == val); } mscore->setMidiRecordId(val); @@ -839,7 +835,7 @@ void PreferenceDialog::updateValues() alsaFragments->setValue(prefs.alsaFragments); drawAntialiased->setChecked(prefs.antialiasedDrawing); - switch(prefs.sessionStart) { + switch (prefs.sessionStart) { case SessionStart::EMPTY: emptySession->setChecked(true); break; case SessionStart::LAST: lastSession->setChecked(true); break; case SessionStart::NEW: newSession->setChecked(true); break; @@ -854,7 +850,7 @@ void PreferenceDialog::updateValues() importLayout->setChecked(prefs.musicxmlImportLayout); importBreaks->setChecked(prefs.musicxmlImportBreaks); exportLayout->setChecked(prefs.musicxmlExportLayout); - switch(prefs.musicxmlExportBreaks) { + switch (prefs.musicxmlExportBreaks) { case MusicxmlExportBreaks::ALL: exportAllBreaks->setChecked(true); break; case MusicxmlExportBreaks::MANUAL: exportManualBreaks->setChecked(true); break; case MusicxmlExportBreaks::NO: exportNoBreaks->setChecked(true); break; @@ -882,7 +878,7 @@ void PreferenceDialog::updateValues() // qDeleteAll(localShortcuts); localShortcuts.clear(); - foreach(const Shortcut* s, Shortcut::shortcuts()) + for (const Shortcut* s: Shortcut::shortcuts()) localShortcuts[s->key()] = new Shortcut(*s); updateSCListView(); @@ -909,11 +905,11 @@ void PreferenceDialog::updateValues() connect(portaudioApi, SIGNAL(activated(int)), SLOT(portaudioApiActivated(int))); #ifdef USE_PORTMIDI PortMidiDriver* midiDriver = static_cast(audio->mididriver()); - if(midiDriver){ + if (midiDriver) { QStringList midiInputs = midiDriver->deviceInList(); int curMidiInIdx = 0; portMidiInput->clear(); - for(int i = 0; i < midiInputs.size(); ++i) { + for (int i = 0; i < midiInputs.size(); ++i) { portMidiInput->addItem(midiInputs.at(i), i); if (midiInputs.at(i) == prefs.portMidiInput) curMidiInIdx = i; @@ -939,7 +935,7 @@ void PreferenceDialog::updateValues() importStyleFile->setText(prefs.importStyleFile); int shortestNoteIndex = 2; int nn = (prefs.shortestNote * 16)/MScore::division; - switch(nn) { + switch (nn) { case 16: shortestNoteIndex = 0; break; case 8: shortestNoteIndex = 1; break; case 4: shortestNoteIndex = 2; break; @@ -955,7 +951,7 @@ void PreferenceDialog::updateValues() int idx = 0; importCharsetListOve->clear(); importCharsetListGP->clear(); - foreach (QByteArray charset, charsets) { + for (QByteArray charset: charsets) { importCharsetListOve->addItem(charset); importCharsetListGP->addItem(charset); if (charset == prefs.importCharsetOve) @@ -970,7 +966,7 @@ void PreferenceDialog::updateValues() language->blockSignals(true); language->clear(); int curIdx = 0; - for(int i = 0; i < mscore->languages().size(); ++i) { + for (int i = 0; i < mscore->languages().size(); ++i) { language->addItem(mscore->languages().at(i).name, i); if (mscore->languages().at(i).key == prefs.language) curIdx = i; @@ -995,15 +991,11 @@ void PreferenceDialog::updateValues() myPlugins->setText(prefs.myPluginsPath); mySoundfonts->setText(prefs.mySoundfontsPath); - idx = 0; - int n = sizeof(exportAudioSampleRates)/sizeof(*exportAudioSampleRates); - for (;idx < n; ++idx) { - if (exportAudioSampleRates[idx] == prefs.exportAudioSampleRate) - break; - } - if (idx == n) // if not found in table - idx = 0; - exportAudioSampleRate->setCurrentIndex(idx); + index = exportAudioSampleRate->findText(QString("%1").arg(prefs.exportAudioSampleRate)); + exportAudioSampleRate->setCurrentIndex(index); + index = exportMp3BitRate->findText(QString("%1").arg(prefs.exportMp3BitRate)); + exportMp3BitRate->setCurrentIndex(index); + exportPdfDpi->setValue(prefs.exportPdfDpi); pageVertical->setChecked(MScore::verticalOrientation()); } @@ -1113,10 +1105,10 @@ void PreferenceDialog::clearShortcutClicked() void PreferenceDialog::filterShortcutsTextChanged(const QString &query ) { QTreeWidgetItem *item; - for(int i = 0; i < shortcutList->topLevelItemCount(); i++) { + for (int i = 0; i < shortcutList->topLevelItemCount(); i++) { item = shortcutList->topLevelItem(i); - if(item->text(0).toLower().contains(query.toLower())) + if (item->text(0).toLower().contains(query.toLower())) item->setHidden(false); else item->setHidden(true); @@ -1263,7 +1255,7 @@ void PreferenceDialog::bgClicked(bool id) void PreferenceDialog::buttonBoxClicked(QAbstractButton* button) { - switch(buttonBox->standardButton(button)) { + switch (buttonBox->standardButton(button)) { case QDialogButtonBox::Apply: apply(); break; @@ -1398,10 +1390,10 @@ void PreferenceDialog::apply() prefs.myImagesPath = myImages->text(); prefs.myTemplatesPath = myTemplates->text(); prefs.myPluginsPath = myPlugins->text(); - prefs.mySoundfontsPath = mySoundfonts->text(); + prefs.mySoundfontsPath = mySoundfonts->text(); - int idx = exportAudioSampleRate->currentIndex(); - prefs.exportAudioSampleRate = exportAudioSampleRates[idx]; + prefs.exportAudioSampleRate = exportAudioSampleRate->currentText().toInt(); + prefs.exportMp3BitRate = exportMp3BitRate->currentText().toInt(); prefs.midiExpandRepeats = expandRepeats->isChecked(); prefs.midiExportRPNs = exportRPNs->isChecked(); @@ -1440,7 +1432,7 @@ void PreferenceDialog::apply() if (shortcutsChanged) { shortcutsChanged = false; - foreach(const Shortcut* s, localShortcuts) { + for (const Shortcut* s: localShortcuts) { Shortcut* os = Shortcut::getShortcut(s->key()); if (os) { if (!os->compareKeys(*s)) @@ -1471,7 +1463,7 @@ void PreferenceDialog::apply() prefs.importStyleFile.clear(); int ticks = MScore::division/4; - switch(shortestNote->currentIndex()) { + switch (shortestNote->currentIndex()) { case 0: ticks = MScore::division; break; case 1: ticks = MScore::division/2; break; case 2: ticks = MScore::division/4; break; @@ -1543,7 +1535,7 @@ void PreferenceDialog::resetAllValues() qDeleteAll(localShortcuts); localShortcuts.clear(); Shortcut::resetToDefault(); - foreach(const Shortcut* s, Shortcut::shortcuts()) + for (const Shortcut* s: Shortcut::shortcuts()) localShortcuts[s->key()] = new Shortcut(*s); updateSCListView(); } @@ -1721,7 +1713,7 @@ void PreferenceDialog::changeSoundfontPaths() PathListDialog pld(this); pld.setWindowTitle(tr("SoundFont Folders")); pld.setPath(mySoundfonts->text()); - if(pld.exec()) + if (pld.exec()) mySoundfonts->setText(pld.path()); } @@ -1826,7 +1818,7 @@ void Preferences::writePluginList() XmlWriter xml(0, &f); xml.header(); xml.stag("museScore version=\"" MSC_VERSION "\""); - foreach(const PluginDescription& d, pluginList) { + for (const PluginDescription& d: pluginList) { xml.stag("Plugin"); xml.tag("path", d.path); xml.tag("load", d.load); @@ -1859,7 +1851,7 @@ static void updatePluginList(QList& pluginPathList, const QString& plug if (fi.isFile()) { if (path.endsWith(".qml")) { bool alreadyInList = false; - foreach (const PluginDescription& p, pluginList) { + for (const PluginDescription& p: pluginList) { if (p.path == path) { alreadyInList = true; break; @@ -1888,7 +1880,7 @@ void Preferences::updatePluginList() pluginPathList.append(mscoreGlobalShare + "plugins"); pluginPathList.append(myPluginsPath); - foreach(QString pluginPath, pluginPathList) { + for (QString pluginPath: pluginPathList) { Ms::updatePluginList(pluginPathList, pluginPath, pluginList); } //remove non existing files diff --git a/mscore/preferences.h b/mscore/preferences.h index 197030206b1cd..9f35d39d71982 100644 --- a/mscore/preferences.h +++ b/mscore/preferences.h @@ -177,6 +177,7 @@ struct Preferences { bool nativeDialogs; int exportAudioSampleRate; + int exportMp3BitRate; QString workspace; int exportPdfDpi; diff --git a/mscore/prefsdialog.ui b/mscore/prefsdialog.ui index c370439046f05..722ccf12cf529 100644 --- a/mscore/prefsdialog.ui +++ b/mscore/prefsdialog.ui @@ -96,7 +96,7 @@ Preferences Tab Manager - 0 + 6 @@ -328,6 +328,9 @@ Select delay (in minutes) between auto saves + + min + 1 @@ -336,13 +339,6 @@ - - - - minutes - - - @@ -703,6 +699,9 @@ Icon Width + + px + 5 @@ -730,6 +729,9 @@ Icon Height + + px + 5 @@ -1094,6 +1096,9 @@ Proximity for selecting elements: + + px + 1 @@ -1187,7 +1192,7 @@ Delay between notes in automatic Real-time mode - ms + ms 300 @@ -1250,7 +1255,7 @@ Default duration - ms + ms 20 @@ -2720,17 +2725,7 @@ true - - - - Period Size: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - + Fragments @@ -2745,7 +2740,37 @@ 8 - 2 + 3 + + + + + + + Device + + + default + + + + + + + Fragments: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Period Size: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -2766,7 +2791,20 @@ - + + + + Qt::Horizontal + + + + 40 + 20 + + + + + Period Size @@ -2774,6 +2812,9 @@ Choose period size + + 2 + 4096 @@ -2811,29 +2852,6 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Fragments: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - @@ -2842,6 +2860,9 @@ Choose sample rate + + 3 + 192000 @@ -2879,16 +2900,26 @@ - - - - Device - + + - default + Hz + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -3345,7 +3376,7 @@ - Resolution DPI: + Resolution: @@ -3380,6 +3411,9 @@ Choose resolution DPI + + DPI + 32 @@ -3429,60 +3463,8 @@ - - - - Audio - - - Audio - - - - - - Sample rate: - - - - - - - Sample rate - - - Choose sample rate - - - - 44100 - - - - - 48000 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - + 0 @@ -3552,15 +3534,15 @@ PDF - - + + - Resolution DPI: + Resolution: - + Resolution DPI @@ -3568,6 +3550,9 @@ Choose resolution DPI + + DPI + 75 @@ -3579,7 +3564,7 @@ - + Qt::Horizontal @@ -3595,6 +3580,162 @@ + + + + Audio + + + Audio + + + + + + 128 + + + 7 + + + + 32 + + + + + 40 + + + + + 48 + + + + + 56 + + + + + 64 + + + + + 80 + + + + + 96 + + + + + 128 + + + + + 112 + + + + + 160 + + + + + 192 + + + + + 224 + + + + + 256 + + + + + 320 + + + + + + + + MP3 Bitrate: + + + + + + + Sample rate: + + + + + + + Sample rate + + + Choose sample rate + + + 0 + + + + 44100 + + + + + 48000 + + + + + + + + Hz + + + + + + + kBit/s + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + +