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
Jojo-Schmitz committed Feb 12, 2017
1 parent bfebf95 commit 47f0726
Show file tree
Hide file tree
Showing 5 changed files with 303 additions and 158 deletions.
9 changes: 5 additions & 4 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 Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions mscore/musescore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5390,6 +5390,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 @@ -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();

Expand Down
78 changes: 35 additions & 43 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;
exportMp3BitRate = 128;

workspace = "Basic";
exportPdfDpi = 300;
Expand Down Expand Up @@ -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);

Expand All @@ -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));
Expand All @@ -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;
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 @@ -501,14 +501,15 @@ 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());
MScore::setVRaster(s.value("vraster", MScore::vRaster()).toInt());

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 @@ -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)));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -909,11 +905,11 @@ void PreferenceDialog::updateValues()
connect(portaudioApi, SIGNAL(activated(int)), SLOT(portaudioApiActivated(int)));
#ifdef USE_PORTMIDI
PortMidiDriver* midiDriver = static_cast<PortMidiDriver*>(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;
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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());
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1859,7 +1851,7 @@ static void updatePluginList(QList<QString>& 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;
Expand Down Expand Up @@ -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
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

0 comments on commit 47f0726

Please sign in to comment.