Fix bug #2905473: GUI Tools: cannot use lame

A lame path option has been added when using MP3 compression. For CLI it can be set using -lame-path. In the GUI it can be set in the advanced MP3 options page. There is also a check on lame in the GUI tools now.

svn-id: r48610
This commit is contained in:
Thierry Crozat
2010-04-10 20:37:06 +00:00
parent 6877be5f8b
commit d25c6505ee
6 changed files with 126 additions and 24 deletions
+13 -2
View File
@@ -49,6 +49,7 @@ struct lameparams {
uint32 algqual;
uint32 vbrqual;
bool silent;
std::string lamePath;
};
struct oggencparams {
@@ -71,7 +72,7 @@ struct rawtype {
uint8 bitsPerSample;
};
lameparams encparms = { minBitrDef, maxBitrDef, false, algqualDef, vbrqualDef, 0 };
lameparams encparms = { minBitrDef, maxBitrDef, false, algqualDef, vbrqualDef, 0, "lame" };
oggencparams oggparms = { -1, -1, -1, (float)oggqualDef, 0 };
flaccparams flacparms = { flacCompressDef, flacBlocksizeDef, false, false };
rawtype rawAudioType = { false, false, 8 };
@@ -124,7 +125,7 @@ void CompressionTool::encodeAudio(const char *inname, bool rawInput, int rawSamp
char *tmp = fbuf;
if (compmode == AUDIO_MP3) {
tmp += sprintf(tmp, "lame -t ");
tmp += sprintf(tmp, "%s -t ", encparms.lamePath.c_str());
if (rawInput) {
tmp += sprintf(tmp, "-r ");
tmp += sprintf(tmp, "--bitwidth %d ", rawAudioType.bitsPerSample);
@@ -774,6 +775,10 @@ void CompressionTool::extractAndEncodeVOC(const char *outName, Common::File &inp
}
// mp3 settings
void CompressionTool::setMp3LamePath(const std::string& arg) {
encparms.lamePath = arg;
}
void CompressionTool::setMp3CompressionType(const std::string& arg) {
encparms.abr = (arg == "ABR");
}
@@ -899,6 +904,11 @@ bool CompressionTool::processMp3Parms() {
encparms.abr = 0;
} else if (arg == "--abr") {
encparms.abr = 1;
} else if (arg == "-lame-path") {
if (_arguments.empty())
throw ToolException("Could not parse command line options, expected value after -lame-path");
setMp3LamePath(_arguments.front());
_arguments.pop_front();
} else if (arg == "-b") {
if (_arguments.empty())
@@ -1103,6 +1113,7 @@ std::string CompressionTool::getHelp() const {
if (_supportedFormats & AUDIO_MP3) {
os << "\nMP3 mode params:\n";
os << " -lame-path <path> Path to the lame excutable to use (default: lame)\n";
os << " -b <rate> <rate> is the target bitrate(ABR)/minimal bitrate(VBR) (default:" << minBitrDef << "%d)\n";
os << " -B <rate> <rate> is the maximum VBR/ABR bitrate (default:%" << maxBitrDef << ")\n";
os << " --vbr LAME uses the VBR mode (default)\n";
+1
View File
@@ -89,6 +89,7 @@ public:
// Settings
// These functions are used by the GUI Tools and by CLI argument parsing functions
// mp3 settings
void setMp3LamePath(const std::string&);
void setMp3CompressionType(const std::string&);
void setMp3MpegQuality(const std::string&);
void setMp3ABRBitrate(const std::string&);
+11
View File
@@ -21,6 +21,7 @@
*/
#include <wx/config.h>
#include <wx/utils.h>
#include "gui/configuration.h"
@@ -37,6 +38,7 @@ Configuration::Configuration() {
advancedAudioSettings = false;
// mp3 params
mp3LamePath = wxT("lame");
mp3CompressionType = wxT("VBR");
mp3MpegQuality = wxT("2");
@@ -67,6 +69,7 @@ void Configuration::load() {
filecnf->Read(wxT("outputpath"), &outputPath);
// mp3 params
filecnf->Read(wxT("mp3LamePath"), &mp3LamePath, mp3LamePath);
filecnf->Read(wxT("mp3CompressionType"), &mp3CompressionType, mp3CompressionType);
filecnf->Read(wxT("mp3MpegQuality"), &mp3MpegQuality, mp3MpegQuality);
filecnf->Read(wxT("mp3ABRBitrate"), &mp3ABRBitrate, mp3ABRBitrate);
@@ -92,6 +95,7 @@ void Configuration::save(bool all) {
wxFileName op(outputPath);
filecnf->Write(wxT("outputpath"), op.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
filecnf->Write(wxT("mp3LamePath"), mp3LamePath);
if (all) {
// mp3 params
@@ -139,3 +143,10 @@ void Configuration::setPlatformDefaults() {
if (selectedPlatform == wxT("Nintendo DS") || selectedPlatform == wxT("Dreamcast"))
selectedAudioFormat = AUDIO_MP3;
}
bool Configuration::isLamePathValid(const wxString& mp3LamePath) {
wxString cmd = mp3LamePath + wxT(" --license");
int retval = wxExecute(cmd, wxEXEC_SYNC);
return retval == 0;
}
+8
View File
@@ -58,6 +58,13 @@ struct Configuration {
* Sets all the compression members to default values based on the 'selectedPlatform' member
*/
void setPlatformDefaults();
/**
* Utility functions that test the given lame path.
*
* @return false indicate that the given lame path does not point to a valid lame executable.
*/
static bool isLamePathValid(const wxString& mp3LamePath);
// While prepending with _ would be in line with the coding conventions
// this class is just a glorified map with different types, so it seems
@@ -84,6 +91,7 @@ struct Configuration {
bool advancedAudioSettings;
// mp3 settings
wxString mp3LamePath;
wxString mp3CompressionType;
wxString mp3MpegQuality;
wxString mp3ABRBitrate;
+1
View File
@@ -146,6 +146,7 @@ void ToolGUI::run(const Configuration &conf) const {
compression->_format = conf.selectedAudioFormat;
// mp3
compression->setMp3LamePath ( (const char *)conf.mp3LamePath.mb_str() );
compression->setMp3CompressionType( (const char *)conf.mp3CompressionType.mb_str() );
compression->setMp3MpegQuality ( (const char *)conf.mp3MpegQuality.mb_str() );
if (conf.mp3CompressionType == wxT("ABR"))
+92 -22
View File
@@ -33,6 +33,8 @@
#include <wx/filepicker.h>
#include <wx/file.h>
#include <wx/process.h>
#include <wx/msgdlg.h>
#include <wx/scrolwin.h>
#include "main.h"
#include "pages.h"
@@ -820,6 +822,29 @@ void ChooseAudioFormatPage::onNext(wxWindow *panel) {
else if (format->GetStringSelection() == wxT("MP3"))
switchPage(new ChooseAudioOptionsMp3Page(_configuration));
} else {
// For MP3 we check if the lame path is valid otherwise we let the choice
// tp the user to either change the audio format or to go to the MP3
// options page (to set the lame path).
if (
format->GetStringSelection() == wxT("MP3") &&
!Configuration::isLamePathValid(_configuration.mp3LamePath)
) {
wxMessageDialog *msgDialog = new wxMessageDialog(
NULL,
wxT("The lame executable could not be found. It is needed to compress files to MP3. "
"You can either proceed to the advanced audio settings page and give the path to lame "
"or you can select another audio format to compress to.\n\n"
"Do you want to proceed to the advanced audio settings page?"),
wxT("lame not found"),
wxYES_NO | wxNO_DEFAULT | wxICON_EXCLAMATION
);
int retval = msgDialog->ShowModal();
if (retval == wxID_YES)
switchPage(new ChooseAudioOptionsMp3Page(_configuration));
return;
}
switchPage(new ProcessPage(_configuration));
}
}
@@ -833,10 +858,20 @@ ChooseAudioOptionsMp3Page::ChooseAudioOptionsMp3Page(Configuration &config)
wxWindow *ChooseAudioOptionsMp3Page::CreatePanel(wxWindow *parent) {
wxWindow *panel = WizardPage::CreatePanel(parent);
wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
// Add a ScrolledWindow in that panel as there is a lot of options
// and there might not be enough place to display them all.
wxScrolledWindow *scroll = new wxScrolledWindow(panel);
scroll->FitInside();
scroll->SetScrollRate(10, 10);
sizer->Add(scroll, 1, wxEXPAND | wxALL);
/*
"\nMP3 mode params:\n"
" -lame-path <path> Path to the lame excutable to use (default: lame)\n"
" -b <rate> <rate> is the target bitrate(ABR)/minimal bitrate(VBR) (default:" minBitrDef_str "%d)\n"
" -B <rate> <rate> is the maximum VBR/ABR bitrate (default:%" maxBitrDef_str ")\n"
" --vbr LAME uses the VBR mode (default)\n"
@@ -846,24 +881,37 @@ wxWindow *ChooseAudioOptionsMp3Page::CreatePanel(wxWindow *parent) {
" --silent the output of LAME is hidden (default:disabled)\n"
*/
wxFlexGridSizer *sizer = new wxFlexGridSizer(6, 2, 10, 25);
sizer->AddGrowableCol(1);
// Grid
wxFlexGridSizer *gridSizer = new wxFlexGridSizer(7, 2, 10, 25);
gridSizer->AddGrowableCol(1);
// Create output selection
gridSizer->Add(new wxStaticText(scroll, wxID_ANY, wxT("Lame executable:")));
wxFilePickerCtrl *lamePicker = new wxFilePickerCtrl(
scroll, wxID_ANY, _configuration.outputPath, wxT("Select lame executable"),
wxT("lame"),
wxDefaultPosition, wxSize(250, -1),
wxFLP_USE_TEXTCTRL | wxFLP_OPEN, wxDefaultValidator,
wxT("LamePath")
);
gridSizer->Add(lamePicker, wxSizerFlags().Expand());
// Type of compression
sizer->Add(new wxStaticText(panel, wxID_ANY, wxT("Compression Type:")));
gridSizer->Add(new wxStaticText(scroll, wxID_ANY, wxT("Compression Type:")));
wxRadioButton *abrButton = new wxRadioButton(panel, wxID_ANY, wxT("ABR"),
wxRadioButton *abrButton = new wxRadioButton(scroll, wxID_ANY, wxT("ABR"),
wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxT("ABR"));
wxSizer *radioSizer = new wxBoxSizer(wxHORIZONTAL);
radioSizer->Add(abrButton);
wxRadioButton *vbrButton = new wxRadioButton(panel, wxID_ANY, wxT("VBR"),
wxRadioButton *vbrButton = new wxRadioButton(scroll, wxID_ANY, wxT("VBR"),
wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxT("VBR"));
radioSizer->Add(vbrButton);
sizer->Add(radioSizer, wxSizerFlags().Expand());
gridSizer->Add(radioSizer, wxSizerFlags().Expand());
// Bitrates
const int possibleBitrateCount = 160 / 8;
@@ -872,28 +920,28 @@ wxWindow *ChooseAudioOptionsMp3Page::CreatePanel(wxWindow *parent) {
possibleBitrates[i] << (i+1)*8;
}
sizer->Add(new wxStaticText(panel, wxID_ANY, wxT("Minimum Bitrate:")));
gridSizer->Add(new wxStaticText(scroll, wxID_ANY, wxT("Minimum Bitrate:")));
wxChoice *vbrMinBitrate = new wxChoice(
panel, wxID_ANY, wxDefaultPosition, wxDefaultSize,
scroll, wxID_ANY, wxDefaultPosition, wxDefaultSize,
possibleBitrateCount, possibleBitrates, 0, wxDefaultValidator, wxT("MinimumBitrate"));
sizer->Add(vbrMinBitrate, wxSizerFlags().Expand().Border(wxRIGHT, 100));
gridSizer->Add(vbrMinBitrate, wxSizerFlags().Expand().Border(wxRIGHT, 100));
sizer->Add(new wxStaticText(panel, wxID_ANY, wxT("Maximum Bitrate:")));
gridSizer->Add(new wxStaticText(scroll, wxID_ANY, wxT("Maximum Bitrate:")));
wxChoice *vbrMaxBitrate = new wxChoice(
panel, wxID_ANY, wxDefaultPosition, wxDefaultSize,
scroll, wxID_ANY, wxDefaultPosition, wxDefaultSize,
possibleBitrateCount, possibleBitrates, 0, wxDefaultValidator, wxT("MaximumBitrate"));
sizer->Add(vbrMaxBitrate, wxSizerFlags().Expand().Border(wxRIGHT, 100));
gridSizer->Add(vbrMaxBitrate, wxSizerFlags().Expand().Border(wxRIGHT, 100));
sizer->Add(new wxStaticText(panel, wxID_ANY, wxT("Average Bitrate:")));
gridSizer->Add(new wxStaticText(scroll, wxID_ANY, wxT("Average Bitrate:")));
wxChoice *abrAvgBitrate = new wxChoice(
panel, wxID_ANY, wxDefaultPosition, wxDefaultSize,
scroll, wxID_ANY, wxDefaultPosition, wxDefaultSize,
possibleBitrateCount, possibleBitrates, 0, wxDefaultValidator, wxT("AverageBitrate"));
sizer->Add(abrAvgBitrate, wxSizerFlags().Expand().Border(wxRIGHT, 100));
gridSizer->Add(abrAvgBitrate, wxSizerFlags().Expand().Border(wxRIGHT, 100));
abrButton->Connect(wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler(ChooseAudioOptionsMp3Page::onChangeCompressionType), NULL, this);
vbrButton->Connect(wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler(ChooseAudioOptionsMp3Page::onChangeCompressionType), NULL, this);
@@ -905,26 +953,28 @@ wxWindow *ChooseAudioOptionsMp3Page::CreatePanel(wxWindow *parent) {
possibleQualities[i] << i;
}
sizer->Add(new wxStaticText(panel, wxID_ANY, wxT("VBR Quality:")));
gridSizer->Add(new wxStaticText(scroll, wxID_ANY, wxT("VBR Quality:")));
wxChoice *vbrQuality = new wxChoice(
panel, wxID_ANY, wxDefaultPosition, wxDefaultSize,
scroll, wxID_ANY, wxDefaultPosition, wxDefaultSize,
possibleQualityCount, possibleQualities, 0, wxDefaultValidator, wxT("VBRQuality"));
sizer->Add(vbrQuality, wxSizerFlags().Expand().Border(wxRIGHT, 100));
gridSizer->Add(vbrQuality, wxSizerFlags().Expand().Border(wxRIGHT, 100));
sizer->Add(new wxStaticText(panel, wxID_ANY, wxT("MPEG Quality:")));
gridSizer->Add(new wxStaticText(scroll, wxID_ANY, wxT("MPEG Quality:")));
wxChoice *mpegQuality = new wxChoice(
panel, wxID_ANY, wxDefaultPosition, wxDefaultSize,
scroll, wxID_ANY, wxDefaultPosition, wxDefaultSize,
possibleQualityCount, possibleQualities, 0, wxDefaultValidator, wxT("MpegQuality"));
sizer->Add(mpegQuality, wxSizerFlags().Expand().Border(wxRIGHT, 100));
gridSizer->Add(mpegQuality, wxSizerFlags().Expand().Border(wxRIGHT, 100));
// Finish the window
scroll->SetSizer(gridSizer);
SetAlignedSizer(panel, sizer);
// Load settings
lamePicker->SetPath(_configuration.mp3LamePath);
if (_configuration.mp3CompressionType == wxT("ABR"))
abrButton->SetValue(true);
else
@@ -941,6 +991,8 @@ wxWindow *ChooseAudioOptionsMp3Page::CreatePanel(wxWindow *parent) {
}
void ChooseAudioOptionsMp3Page::save(wxWindow *panel) {
wxFilePickerCtrl *lamePath = static_cast<wxFilePickerCtrl *>(panel->FindWindowByName(wxT("LamePath")));
wxRadioButton *abr = static_cast<wxRadioButton *>(panel->FindWindowByName(wxT("ABR")));
// wxRadioButton *vbr = static_cast<wxRadioButton *>(panel->FindWindowByName(wxT("VBR")));
@@ -950,6 +1002,7 @@ void ChooseAudioOptionsMp3Page::save(wxWindow *panel) {
wxChoice *vbrQuality = static_cast<wxChoice *>(panel->FindWindowByName(wxT("VBRQuality")));
wxChoice *mpegQuality = static_cast<wxChoice *>(panel->FindWindowByName(wxT("MpegQuality")));
_configuration.mp3LamePath = lamePath->GetPath();
_configuration.mp3VBRMinBitrate = vbrMinBitrate->GetStringSelection();
_configuration.mp3VBRMaxBitrate = vbrMaxBitrate->GetStringSelection();
_configuration.mp3ABRBitrate = abrAvgBitrate->GetStringSelection();
@@ -984,6 +1037,23 @@ void ChooseAudioOptionsMp3Page::onChangeCompressionType(wxCommandEvent &evt) {
}
void ChooseAudioOptionsMp3Page::onNext(wxWindow *panel) {
// Check if the lame path is valid.
// The configuration is updated when calling switchPage() and therefore
// is not yet up to date. So we get the path from the wxFilePickerCtrl
wxFilePickerCtrl *lamePath = static_cast<wxFilePickerCtrl *>(panel->FindWindowByName(wxT("LamePath")));
if (!Configuration::isLamePathValid(lamePath->GetPath())) {
wxMessageDialog *msgDialog = new wxMessageDialog(
NULL,
wxT("The lame executable could not be found. It is needed to compress files to MP3. "
"If you want to use MP3 compression you need to select a valid lame executable. "
"Otherwise you can go back to the audio format selection and select another format."),
wxT("lame not found"),
wxOK | wxICON_EXCLAMATION
);
msgDialog->ShowModal();
return;
}
switchPage(new ProcessPage(_configuration));
}