210 lines
6.1 KiB
C++
210 lines
6.1 KiB
C++
#include <guitar/SettingsDlg.hpp>
|
|
#include <guitar/registry.hpp>
|
|
#include <guitar/GlobalDefs.hpp>
|
|
#include <guitar/Timing.hpp>
|
|
#include <guitar/guitar.hpp>
|
|
#include <midiseq/midiout.hpp>
|
|
|
|
SettingsDialog::SettingsDialog(void)
|
|
{
|
|
mInitHandler.setCallback(this,&SettingsDialog::initHandler);
|
|
mCreateHandler.setCallback(this,&SettingsDialog::createHandler);
|
|
mCloseHandler.setCallback(this,&SettingsDialog::closeHandler);
|
|
mDestroyHandler.setCallback(this,&SettingsDialog::destroyHandler);
|
|
mCommandHandler.setCallback(this,&SettingsDialog::commandHandler);
|
|
insertHandler(VectorHandler::InitDialogHandler,&mInitHandler);
|
|
insertHandler(VectorHandler::CreateHandler,&mCreateHandler);
|
|
insertHandler(VectorHandler::CloseHandler,&mCloseHandler);
|
|
insertHandler(VectorHandler::CommandHandler,&mCommandHandler);
|
|
insertHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
|
|
}
|
|
|
|
SettingsDialog::SettingsDialog(const SettingsDialog &someSettingsDialog)
|
|
{ // private implementation
|
|
*this=someSettingsDialog;
|
|
}
|
|
|
|
SettingsDialog::~SettingsDialog()
|
|
{
|
|
removeHandler(VectorHandler::InitDialogHandler,&mInitHandler);
|
|
removeHandler(VectorHandler::CreateHandler,&mCreateHandler);
|
|
removeHandler(VectorHandler::CloseHandler,&mCloseHandler);
|
|
removeHandler(VectorHandler::CommandHandler,&mCommandHandler);
|
|
removeHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
|
|
}
|
|
|
|
SettingsDialog &SettingsDialog::operator=(const SettingsDialog &someSettingsDialog)
|
|
{ // private implementation
|
|
return *this;
|
|
}
|
|
|
|
bool SettingsDialog::perform(GUIWindow &parentWindow)
|
|
{
|
|
Rect clientRect;
|
|
parentWindow.clientRect(clientRect);
|
|
mDisplayPoint.x((clientRect.right()-clientRect.left())/2);
|
|
mDisplayPoint.y((clientRect.bottom()-clientRect.top())/2);
|
|
return ::DialogBoxParam(processInstance(),(LPSTR)"SETTINGSDIALOG",(HWND)parentWindow,DWindow::DlgProc,(LPARAM)(DWindow*)this);
|
|
}
|
|
|
|
CallbackData::ReturnType SettingsDialog::initHandler(CallbackData &someCallbackData)
|
|
{
|
|
mDisplayPoint.x(mDisplayPoint.x()-(width()/2));
|
|
mDisplayPoint.y(mDisplayPoint.y()-(height()/2));
|
|
move(mDisplayPoint);
|
|
initialize();
|
|
return (CallbackData::ReturnType)false;
|
|
}
|
|
|
|
CallbackData::ReturnType SettingsDialog::createHandler(CallbackData &someCallbackData)
|
|
{
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
CallbackData::ReturnType SettingsDialog::closeHandler(CallbackData &someCallbackData)
|
|
{
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
CallbackData::ReturnType SettingsDialog::destroyHandler(CallbackData &someCallbackData)
|
|
{
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
CallbackData::ReturnType SettingsDialog::commandHandler(CallbackData &someCallbackData)
|
|
{
|
|
switch(someCallbackData.wmCommandID())
|
|
{
|
|
case IDCANCEL :
|
|
endDialog(false);
|
|
break;
|
|
case IDOK :
|
|
apply();
|
|
break;
|
|
case SETTINGS_DEFAULTS :
|
|
selectDefaults();
|
|
}
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
void SettingsDialog::initialize(void)
|
|
{
|
|
Registry registry;
|
|
|
|
sendMessage(SETTINGS_INSTRUMENT,CB_RESETCONTENT,0,0L);
|
|
for(int index=0;index<mInstruments.size();index++)
|
|
sendMessage(SETTINGS_INSTRUMENT,CB_INSERTSTRING,-1,(LPARAM)(LPSTR)mInstruments[index].description());
|
|
selectTiming(registry.getMicrosecondsPerQuarterNote());
|
|
selectInstrument(registry.getInstrument());
|
|
selectAction(registry.getShowAction());
|
|
selectShowNotes(registry.getShowNotes());
|
|
selectMIDIOutputDevice(registry.getMIDIOutputDevice());
|
|
}
|
|
|
|
void SettingsDialog::selectInstrument(Instrument instrument)
|
|
{
|
|
if(!instrument.isOkay())
|
|
{
|
|
Registry registry;
|
|
registry.setInstrument(mInstruments[0]);
|
|
sendMessage(SETTINGS_INSTRUMENT,CB_SETCURSEL,0,0L);
|
|
}
|
|
else
|
|
{
|
|
int index;
|
|
index=sendMessage(SETTINGS_INSTRUMENT,CB_FINDSTRINGEXACT,-1,(LPARAM)(LPSTR)instrument.description());
|
|
sendMessage(SETTINGS_INSTRUMENT,CB_SETCURSEL,index,0L);
|
|
}
|
|
}
|
|
|
|
Instrument SettingsDialog::getInstrument(void)
|
|
{
|
|
String strInstrument;
|
|
int index=sendMessage(SETTINGS_INSTRUMENT,CB_GETCURSEL,0,0L);
|
|
return mInstruments.getInstrument(index);
|
|
}
|
|
|
|
bool SettingsDialog::getAction(void)
|
|
{
|
|
return sendMessage(SETTINGS_SHOWACTION,BM_GETCHECK,0,0);
|
|
}
|
|
|
|
bool SettingsDialog::getShowNotes(void)
|
|
{
|
|
return sendMessage(SETTINGS_SHOWNOTES,BM_GETCHECK,0,0);
|
|
}
|
|
|
|
int SettingsDialog::getTiming(void)
|
|
{
|
|
String strText;
|
|
|
|
getText(SETTINGS_MICROSECSPERQTRNOTE,strText);
|
|
return strText.toInt();
|
|
}
|
|
|
|
String SettingsDialog::getMIDIOutputDevice(void)
|
|
{
|
|
int currentSelection;
|
|
String midiOutputDevice;
|
|
|
|
currentSelection=sendMessage(SETTINGS_MIDIOUT,CB_GETCURSEL,0,0L);
|
|
sendMessage(SETTINGS_MIDIOUT,CB_GETLBTEXT,currentSelection,(LPARAM)midiOutputDevice.str());
|
|
return midiOutputDevice;
|
|
}
|
|
|
|
void SettingsDialog::selectDefaults()
|
|
{
|
|
Instruments instruments;
|
|
|
|
selectInstrument(instruments[0]);
|
|
selectTiming(GlobalDefs::MicrosecondsPerQuarterNote);
|
|
selectAction(GlobalDefs::ShowAction);
|
|
selectShowNotes(GlobalDefs::ShowNotes);
|
|
}
|
|
|
|
void SettingsDialog::selectTiming(int timing)
|
|
{
|
|
setText(SETTINGS_MICROSECSPERQTRNOTE,String().fromInt(timing));
|
|
}
|
|
|
|
void SettingsDialog::selectAction(bool action)
|
|
{
|
|
sendMessage(SETTINGS_SHOWACTION,BM_SETCHECK,action,0);
|
|
}
|
|
|
|
void SettingsDialog::selectShowNotes(bool showNotes)
|
|
{
|
|
sendMessage(SETTINGS_SHOWNOTES,BM_SETCHECK,showNotes,0);
|
|
}
|
|
|
|
void SettingsDialog::selectMIDIOutputDevice(const String &midiOutputDeviceName)
|
|
{
|
|
Block<String> deviceNames;
|
|
int currentSelection=-1;
|
|
|
|
MIDIOutputDevice::getDeviceNames(deviceNames);
|
|
sendMessage(SETTINGS_MIDIOUT,CB_RESETCONTENT,0,0L);
|
|
deviceNames.insert(&String("MIDIMAPPER"));
|
|
for(int index=0;index<deviceNames.size();index++)
|
|
{
|
|
sendMessage(SETTINGS_MIDIOUT,CB_ADDSTRING,0,(LPARAM)deviceNames[index].str());
|
|
if(midiOutputDeviceName==deviceNames[index])currentSelection=index;
|
|
}
|
|
if(-1==currentSelection)currentSelection=0;
|
|
sendMessage(SETTINGS_MIDIOUT,CB_SETCURSEL,currentSelection,0L);
|
|
}
|
|
|
|
void SettingsDialog::apply()
|
|
{
|
|
Registry registry;
|
|
int microsecondsPerQuarterNote;
|
|
|
|
microsecondsPerQuarterNote=getTiming();
|
|
registry.setShowAction(getAction());
|
|
registry.setMicrosecondsPerQuarterNote(microsecondsPerQuarterNote);
|
|
registry.setInstrument(getInstrument());
|
|
Timing::microsecondsPerQuarterNote(microsecondsPerQuarterNote);
|
|
registry.setShowNotes(getShowNotes());
|
|
registry.setMIDIOutputDevice(getMIDIOutputDevice());
|
|
}
|