Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #50926: add setting and option for MP3 bitrate #2993

Merged
merged 1 commit into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -5393,6 +5393,7 @@ int main(int argc, char* av[])
parser.addOption(QCommandLineOption({"P", "export-score-parts"}, "Used with -o <file>.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 <file>.mp3, sets bitrate", "bitrate"));

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

Expand Down Expand Up @@ -5504,6 +5505,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
91 changes: 66 additions & 25 deletions mscore/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ bool useALSA = false, useJACK = false, usePortaudio = false, usePulseAudio = fal

extern bool externalStyle;

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

//---------------------------------------------------------
// Preferences
//---------------------------------------------------------
Expand Down Expand Up @@ -201,7 +199,8 @@ void Preferences::init()
#else
nativeDialogs = false; // don't use system native file dialogs
#endif
exportAudioSampleRate = exportAudioSampleRates[0];
exportAudioSampleRate = 44100;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's wrong with exportAudioSampleRates[0] ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted it, it was superfluos and duplicated from the pull down menu

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not as superfluos as I though though...

exportMp3BitRate = 128;

workspace = "Basic";
exportPdfDpi = 300;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -589,7 +590,54 @@ PreferenceDialog::PreferenceDialog(QWidget* parent)
#endif
#ifndef USE_ALSA
alsaDriver->setVisible(false);
#else
exportAudioSampleRate->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 @@ -664,11 +712,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)));
Expand Down Expand Up @@ -832,9 +875,10 @@ 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 @@ -995,15 +1039,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 @@ -1343,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 @@ -1353,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 @@ -1400,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 @@ -177,6 +177,7 @@ struct Preferences {
bool nativeDialogs;

int exportAudioSampleRate;
int exportMp3BitRate;

QString workspace;
int exportPdfDpi;
Expand Down
Loading