Skip to content

Commit

Permalink
fix #50926: add setting and option for MP3 bitrate
Browse files Browse the repository at this point in the history
  • Loading branch information
lasconic committed Feb 17, 2017
1 parent f28e279 commit 0d1bd52
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 148 deletions.
1 change: 1 addition & 0 deletions mscore/exportmp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions mscore/musescore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4970,6 +4970,7 @@ int main(int argc, char* av[])
parser.addOption(QCommandLineOption({"w", "no-webview"}, "No web view in start center"));
parser.addOption(QCommandLineOption({"P", "export-score-parts"}, "Used with -o <file>.pdf, export score + parts"));
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 <file>.mp3, sets bitrate", "bitrate"));

parser.addPositionalArgument("scorefiles", "The files to open", "[scorefile...]");

Expand Down Expand Up @@ -5080,6 +5081,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();

Expand Down
90 changes: 65 additions & 25 deletions mscore/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ bool useALSA = false, useJACK = false, usePortaudio = false, usePulseAudio = fal

extern bool externalStyle;

static int exportAudioSampleRates[2] = { 44100, 48000 };

//---------------------------------------------------------
// Preferences
//---------------------------------------------------------
Expand Down Expand Up @@ -195,7 +193,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;
Expand Down Expand Up @@ -323,6 +322,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);
Expand Down Expand Up @@ -493,6 +493,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();
Expand Down Expand Up @@ -585,7 +586,54 @@ PreferenceDialog::PreferenceDialog(QWidget* parent)
#endif
#ifndef USE_ALSA
alsaDriver->setVisible(false);
#else
alsaSampleRate->clear();
alsaSampleRate->addItem(tr("192000"), 192000);
alsaSampleRate->addItem( tr("96000"), 96000);
alsaSampleRate->addItem( tr("88200"), 88200);
alsaSampleRate->addItem( tr("48000"), 48000); // default
alsaSampleRate->addItem( tr("44100"), 44100);
alsaSampleRate->addItem( tr("32000"), 32000);
alsaSampleRate->addItem( tr("22050"), 22050);

alsaPeriodSize->clear();
alsaPeriodSize->addItem(tr("4096"), 4096);
alsaPeriodSize->addItem(tr("2048"), 2048);
alsaPeriodSize->addItem(tr("1024"), 1024); // default
alsaPeriodSize->addItem( tr("512"), 512);
alsaPeriodSize->addItem( tr("256"), 256);
alsaPeriodSize->addItem( tr("128"), 128);
alsaPeriodSize->addItem( tr("64"), 64);
#endif

exportAudioSampleRate->clear();
exportAudioSampleRate->addItem(tr("44100"), 44100); // default
exportAudioSampleRate->addItem(tr("48000"), 48000);

#ifndef USE_LAME
exportMp3BitRateLabel->setVisible(false);
exportMp3BitRate->setVisible(false);
exporMp3BitRateUnit->setVisible(false)
#else
exportMp3BitRate->clear();
exportMp3BitRate->addItem( tr("8"), 8);
exportMp3BitRate->addItem( tr("16"), 16);
exportMp3BitRate->addItem( tr("32"), 32);
exportMp3BitRate->addItem( tr("40"), 40);
exportMp3BitRate->addItem( tr("48"), 48);
//exportMp3BitRate->addItem( tr("56"), 56);
exportMp3BitRate->addItem( tr("64"), 64);
exportMp3BitRate->addItem( tr("80"), 80);
exportMp3BitRate->addItem( tr("96"), 96);
exportMp3BitRate->addItem(tr("112"), 112);
exportMp3BitRate->addItem(tr("128"), 128); // default
exportMp3BitRate->addItem(tr("160"), 160);
exportMp3BitRate->addItem(tr("192"), 192);
exportMp3BitRate->addItem(tr("224"), 224);
exportMp3BitRate->addItem(tr("256"), 256);
exportMp3BitRate->addItem(tr("320"), 320);
#endif

#ifndef USE_PORTAUDIO
portaudioDriver->setVisible(false);
#endif
Expand Down Expand Up @@ -659,11 +707,6 @@ PreferenceDialog::PreferenceDialog(QWidget* parent)
recordButtons->addButton(recordUndo, RMIDI_UNDO);
recordButtons->addButton(recordEditMode, RMIDI_NOTE_EDIT_MODE);

int n = sizeof(exportAudioSampleRates)/sizeof(*exportAudioSampleRates);
exportAudioSampleRate->clear();
for (int idx = 0; idx < n; ++idx)
exportAudioSampleRate->addItem(QString("%1").arg(exportAudioSampleRates[idx]));

restartWarningLanguage->setText("");
connect(language, SIGNAL(currentIndexChanged(int)), SLOT(languageChanged(int)));

Expand Down Expand Up @@ -836,9 +879,9 @@ void PreferenceDialog::updateValues()

alsaDevice->setText(prefs.alsaDevice);

int index = alsaSampleRate->findText(QString("%1").arg(prefs.alsaSampleRate));
int index = alsaSampleRate->findData(prefs.alsaSampleRate);
alsaSampleRate->setCurrentIndex(index);
index = alsaPeriodSize->findText(QString("%1").arg(prefs.alsaPeriodSize));
index = alsaPeriodSize->findData(prefs.alsaPeriodSize);
alsaPeriodSize->setCurrentIndex(index);

alsaFragments->setValue(prefs.alsaFragments);
Expand Down Expand Up @@ -998,15 +1041,12 @@ 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->findData(prefs.exportAudioSampleRate);
exportAudioSampleRate->setCurrentIndex(index);

index = exportMp3BitRate->findData(prefs.exportMp3BitRate);
exportMp3BitRate->setCurrentIndex(index);

exportPdfDpi->setValue(prefs.exportPdfDpi);
pageVertical->setChecked(MScore::verticalOrientation());
}
Expand Down Expand Up @@ -1344,8 +1384,8 @@ void PreferenceDialog::apply()
|| (prefs.usePortaudioAudio != portaudioDriver->isChecked())
|| (prefs.usePulseAudio != pulseaudioDriver->isChecked())
|| (prefs.alsaDevice != alsaDevice->text())
|| (prefs.alsaSampleRate != alsaSampleRate->currentText().toInt())
|| (prefs.alsaPeriodSize != alsaPeriodSize->currentText().toInt())
|| (prefs.alsaSampleRate != alsaSampleRate->currentData().toInt())
|| (prefs.alsaPeriodSize != alsaPeriodSize->currentData().toInt())
|| (prefs.alsaFragments != alsaFragments->value())
) {
if (seq)
Expand All @@ -1354,8 +1394,8 @@ void PreferenceDialog::apply()
prefs.usePortaudioAudio = portaudioDriver->isChecked();
prefs.usePulseAudio = pulseaudioDriver->isChecked();
prefs.alsaDevice = alsaDevice->text();
prefs.alsaSampleRate = alsaSampleRate->currentText().toInt();
prefs.alsaPeriodSize = alsaPeriodSize->currentText().toInt();
prefs.alsaSampleRate = alsaSampleRate->currentData().toInt();
prefs.alsaPeriodSize = alsaPeriodSize->currentData().toInt();
prefs.alsaFragments = alsaFragments->value();
preferences = prefs;
if (seq) {
Expand Down Expand Up @@ -1401,8 +1441,8 @@ void PreferenceDialog::apply()
prefs.myPluginsPath = myPlugins->text();
prefs.mySoundfontsPath = mySoundfonts->text();

int idx = exportAudioSampleRate->currentIndex();
prefs.exportAudioSampleRate = exportAudioSampleRates[idx];
prefs.exportAudioSampleRate = exportAudioSampleRate->currentData().toInt();
prefs.exportMp3BitRate = exportMp3BitRate->currentData().toInt();

prefs.midiExpandRepeats = expandRepeats->isChecked();
prefs.midiExportRPNs = exportRPNs->isChecked();
Expand Down
1 change: 1 addition & 0 deletions mscore/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ struct Preferences {
bool nativeDialogs;

int exportAudioSampleRate;
int exportMp3BitRate;

QString workspace;
int exportPdfDpi;
Expand Down
Loading

0 comments on commit 0d1bd52

Please sign in to comment.