1
// RCS-ID: $Id: MidiWizard.cpp,v 1.3 2006/02/23 19:17:12 cecilios Exp $
2
//--------------------------------------------------------------------------------------
3
// LenMus Phonascus: The teacher of music
4
// Copyright (c) 2002-2006 Cecilio Salmeron
6
// This program is free software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the Free Software Foundation;
8
// either version 2 of the License, or (at your option) any later version.
10
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
11
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License along with this
15
// program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
16
// Fifth Floor, Boston, MA 02110-1301, USA.
18
// For any comment, suggestion or feature request, please contact the manager of
19
// the project at cecilios@users.sourceforge.net
21
//-------------------------------------------------------------------------------------
22
/*! @file MidiWizard.cpp
23
@brief Implementation file for class lmMidiWizard
26
#if defined(__GNUG__) && !defined(__APPLE__)
27
#pragma implementation "MidiWizard.h"
30
// For compilers that support precompilation, includes "wx/wx.h".
31
#include "wx/wxprec.h"
44
#include "MidiWizard.h"
46
// MIDI support throgh Portmidi lib
47
#include "../../wxMidi/include/wxMidi.h"
49
//access to Midi configuration
50
#include "../sound/MidiManager.h"
56
* lmMidiWizard type definition
59
IMPLEMENT_DYNAMIC_CLASS( lmMidiWizard, wxWizard )
62
* lmMidiWizard event table definition
65
BEGIN_EVENT_TABLE( lmMidiWizard, wxWizard )
67
////@begin lmMidiWizard event table entries
68
EVT_WIZARD_CANCEL( ID_WIZARD, lmMidiWizard::OnWizardCancel )
69
EVT_WIZARD_FINISHED( ID_WIZARD, lmMidiWizard::OnWizardFinished )
71
////@end lmMidiWizard event table entries
76
* lmMidiWizard constructors
79
lmMidiWizard::lmMidiWizard( )
83
lmMidiWizard::lmMidiWizard( wxWindow* parent, wxWindowID id, const wxPoint& pos )
85
Create(parent, id, pos);
89
* lmMidiWizard creator
92
bool lmMidiWizard::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos )
94
////@begin lmMidiWizard member initialisation
95
m_pMtrChannelCombo = NULL;
96
////@end lmMidiWizard member initialisation
98
////@begin lmMidiWizard creation
99
SetExtraStyle(GetExtraStyle()|wxWIZARD_EX_HELPBUTTON);
100
wxBitmap wizardBitmap(wxNullBitmap);
101
wxWizard::Create( parent, id, _("MIDI configuration wizard"), wizardBitmap, pos );
104
////@end lmMidiWizard creation
106
//save current Midi configuration to restore it if the wizard is cancelled
107
m_nOldInDevId = g_pMidi->InDevId();
108
m_nOldOutDevId = g_pMidi->OutDevId();
109
m_nOldVoiceInstr = g_pMidi->VoiceInstr();
110
m_nOldVoiceChannel = g_pMidi->VoiceChannel();
111
m_nOldMtrInstr = g_pMidi->MtrInstr();
112
m_nOldMtrChannel = g_pMidi->MtrChannel();
113
m_nOldMtrTone1 = g_pMidi->MtrTone1();
114
m_nOldMtrTone2 = g_pMidi->MtrTone2();
120
* Control creation for lmMidiWizard
123
void lmMidiWizard::CreateControls()
125
////@begin lmMidiWizard content construction
126
wxWizard* itemWizard1 = this;
128
WizardDevicesPage* itemWizardPageSimple2 = new WizardDevicesPage( itemWizard1 );
130
itemWizard1->FitToPage(itemWizardPageSimple2);
131
WizardInstrumentsPage* itemWizardPageSimple16 = new WizardInstrumentsPage( itemWizard1 );
133
itemWizard1->FitToPage(itemWizardPageSimple16);
134
m_pMtrChannelCombo = new WizardMetronomePage( itemWizard1 );
136
itemWizard1->FitToPage(m_pMtrChannelCombo);
137
wxWizardPageSimple* lastPage = NULL;
139
wxWizardPageSimple::Chain(lastPage, itemWizardPageSimple2);
140
lastPage = itemWizardPageSimple2;
142
wxWizardPageSimple::Chain(lastPage, itemWizardPageSimple16);
143
lastPage = itemWizardPageSimple16;
145
wxWizardPageSimple::Chain(lastPage, m_pMtrChannelCombo);
146
lastPage = m_pMtrChannelCombo;
147
////@end lmMidiWizard content construction
154
bool lmMidiWizard::Run()
156
wxWizardPage* startPage = NULL;
157
wxWindowListNode* node = GetChildren().GetFirst();
160
wxWizardPage* startPage = wxDynamicCast(node->GetData(), wxWizardPage);
161
if (startPage) return RunWizard(startPage);
162
node = node->GetNext();
168
* Should we show tooltips?
171
bool lmMidiWizard::ShowToolTips()
177
* Get bitmap resources
180
wxBitmap lmMidiWizard::GetBitmapResource( const wxString& name )
183
////@begin lmMidiWizard bitmap retrieval
185
////@end lmMidiWizard bitmap retrieval
192
wxIcon lmMidiWizard::GetIconResource( const wxString& name )
195
////@begin lmMidiWizard icon retrieval
197
////@end lmMidiWizard icon retrieval
201
* wxEVT_WIZARD_FINISHED event handler for ID_WIZARD
204
void lmMidiWizard::OnWizardFinished( wxWizardEvent& event )
206
//take note that user has set Midi preferences
207
g_pMidi->SetConfigured(true);
209
//and save user MIDI preferences
210
g_pMidi->SaveUserPreferences();
215
* wxEVT_WIZARD_CANCEL event handler for ID_WIZARD
218
void lmMidiWizard::OnWizardCancel( wxWizardEvent& event )
221
restore old configuration
225
g_pMidi->SetInDevice(m_nOldInDevId);
226
g_pMidi->SetOutDevice(m_nOldOutDevId);
229
g_pMidi->VoiceChange(m_nOldVoiceChannel, m_nOldVoiceInstr);
231
//metronome configuration
232
g_pMidi->VoiceChange(m_nOldMtrChannel, m_nOldMtrInstr);
233
g_pMidi->SetMetronomeTones(m_nOldMtrTone1, m_nOldMtrTone2);
236
wxMessageBox(_("Midi set up cancelled. Old configuration restored."));
242
* WizardDevicesPage type definition
245
IMPLEMENT_DYNAMIC_CLASS( WizardDevicesPage, wxWizardPageSimple )
248
* WizardDevicesPage event table definition
251
BEGIN_EVENT_TABLE( WizardDevicesPage, wxWizardPageSimple )
253
////@begin WizardDevicesPage event table entries
254
////@end WizardDevicesPage event table entries
259
* WizardDevicesPage constructors
262
WizardDevicesPage::WizardDevicesPage( )
266
WizardDevicesPage::WizardDevicesPage( wxWizard* parent )
275
bool WizardDevicesPage::Create( wxWizard* parent )
277
////@begin WizardDevicesPage member initialisation
280
////@end WizardDevicesPage member initialisation
282
////@begin WizardDevicesPage creation
283
wxBitmap wizardBitmap(GetBitmapResource(wxT("wizard.png")));
284
wxWizardPageSimple::Create( parent, NULL, NULL, wizardBitmap );
287
GetSizer()->Fit(this);
288
////@end WizardDevicesPage creation
290
// populate combo boxes with available Midi devices
291
int nItem, nInput=0, nOutput=0;
292
int nNumDevices = g_pMidiSystem->CountDevices();
293
for (int i = 0; i < nNumDevices; i++) {
294
wxMidiOutDevice* pMidiDev = new wxMidiOutDevice(i);
295
if (pMidiDev->IsOutputPort()) {
297
nItem = m_pOutCombo->Append( pMidiDev->DeviceName() );
298
m_pOutCombo->SetClientData(nItem, (void *)i);
300
if (pMidiDev->IsInputPort()) {
302
nItem = m_pInCombo->Append( pMidiDev->DeviceName() );
303
m_pInCombo->SetClientData(nItem, (void *)i);
308
nItem = m_pInCombo->Append( _("None") );
309
m_pInCombo->SetClientData(nItem, (void *)(-1));
312
nItem = m_pOutCombo->Append( _("None") );
313
m_pOutCombo->SetClientData(nItem, (void *)(-1));
315
m_pOutCombo->SetSelection(0);
316
m_pInCombo->SetSelection(0);
322
* Control creation for WizardPage
325
void WizardDevicesPage::CreateControls()
327
////@begin WizardDevicesPage content construction
328
WizardDevicesPage* itemWizardPageSimple2 = this;
330
wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
331
itemWizardPageSimple2->SetSizer(itemBoxSizer3);
333
wxBoxSizer* itemBoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
334
itemBoxSizer3->Add(itemBoxSizer4, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
336
wxStaticText* itemStaticText5 = new wxStaticText( itemWizardPageSimple2, wxID_STATIC, _("Midi devices to use"), wxDefaultPosition, wxDefaultSize, 0 );
337
itemStaticText5->SetFont(wxFont(14, wxSWISS, wxNORMAL, wxBOLD, FALSE, _T("Arial")));
338
itemBoxSizer4->Add(itemStaticText5, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
340
wxBoxSizer* itemBoxSizer6 = new wxBoxSizer(wxHORIZONTAL);
341
itemBoxSizer3->Add(itemBoxSizer6, 1, wxGROW|wxALL, 5);
343
wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxVERTICAL);
344
itemBoxSizer6->Add(itemBoxSizer7, 1, wxGROW|wxALL, 5);
346
wxStaticText* itemStaticText8 = new wxStaticText( itemWizardPageSimple2, wxID_STATIC, _("To generate sounds the program needs a MIDI synthesizer device. Normally, one of these devices is included in the sound board of the PC, but your PC might have more than one."), wxDefaultPosition, wxSize(250, -1), 0 );
347
itemBoxSizer7->Add(itemStaticText8, 1, wxGROW|wxALL|wxADJUST_MINSIZE, 5);
349
wxStaticText* itemStaticText9 = new wxStaticText( itemWizardPageSimple2, wxID_STATIC, _("If your PC has more than one device, choose one of them. You can test all of them and choose the one whose sound you prefer."), wxDefaultPosition, wxSize(250, -1), 0 );
350
itemBoxSizer7->Add(itemStaticText9, 1, wxGROW|wxALL|wxADJUST_MINSIZE, 5);
352
wxStaticLine* itemStaticLine10 = new wxStaticLine( itemWizardPageSimple2, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL );
353
itemBoxSizer6->Add(itemStaticLine10, 0, wxGROW|wxALL, 5);
355
wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxVERTICAL);
356
itemBoxSizer6->Add(itemBoxSizer11, 1, wxGROW|wxALL, 5);
358
wxStaticText* itemStaticText12 = new wxStaticText( itemWizardPageSimple2, wxID_STATIC, _("Output device:"), wxDefaultPosition, wxDefaultSize, 0 );
359
itemBoxSizer11->Add(itemStaticText12, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5);
361
wxString* m_pOutComboStrings = NULL;
362
m_pOutCombo = new wxComboBox( itemWizardPageSimple2, ID_COMBO_OUT_DEVICES, _T(""), wxDefaultPosition, wxSize(250, -1), 0, m_pOutComboStrings, wxCB_DROPDOWN );
363
itemBoxSizer11->Add(m_pOutCombo, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxBOTTOM, 5);
365
wxStaticText* itemStaticText14 = new wxStaticText( itemWizardPageSimple2, wxID_STATIC, _("Input device:"), wxDefaultPosition, wxDefaultSize, 0 );
366
itemBoxSizer11->Add(itemStaticText14, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5);
368
wxString* m_pInComboStrings = NULL;
369
m_pInCombo = new wxComboBox( itemWizardPageSimple2, ID_COMBO_IN_DEVICES, _T(""), wxDefaultPosition, wxSize(250, -1), 0, m_pInComboStrings, wxCB_DROPDOWN );
370
itemBoxSizer11->Add(m_pInCombo, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxBOTTOM, 5);
372
////@end WizardDevicesPage content construction
376
* Should we show tooltips?
379
bool WizardDevicesPage::ShowToolTips()
385
* Get bitmap resources
388
wxBitmap WizardDevicesPage::GetBitmapResource( const wxString& name )
391
////@begin WizardDevicesPage bitmap retrieval
392
if (name == wxT("wizard.png"))
394
wxBitmap bitmap(_T("wizard.png"), wxBITMAP_TYPE_PNG);
398
////@end WizardDevicesPage bitmap retrieval
405
wxIcon WizardDevicesPage::GetIconResource( const wxString& name )
408
////@begin WizardDevicesPage icon retrieval
410
////@end WizardDevicesPage icon retrieval
413
bool WizardDevicesPage::TransferDataFromWindow()
416
Save temporary data and open temporary Midi Devices
419
//get number of Midi device to use for output
420
int nIndex = m_pOutCombo->GetSelection();
421
int nOutDevId = (int) m_pOutCombo->GetClientData(nIndex);
422
g_pMidi->SetOutDevice(nOutDevId);
426
if (m_pInCombo->GetStringSelection() != _("None") ) {
427
nIndex = m_pInCombo->GetSelection();
428
nInDevId = (int) m_pInCombo->GetClientData(nIndex);
430
g_pMidi->SetInDevice(nInDevId);
439
* WizardInstrumentsPage type definition
442
IMPLEMENT_DYNAMIC_CLASS( WizardInstrumentsPage, wxWizardPageSimple )
445
* WizardInstrumentsPage event table definition
448
BEGIN_EVENT_TABLE( WizardInstrumentsPage, wxWizardPageSimple )
450
////@begin WizardInstrumentsPage event table entries
451
EVT_COMBOBOX( ID_COMBO_SECTION, WizardInstrumentsPage::OnComboSection )
453
EVT_COMBOBOX( ID_COMBO_INSTRUMENT, WizardInstrumentsPage::OnComboInstrument )
455
EVT_BUTTON( ID_BUTTON_TEST_SOUND, WizardInstrumentsPage::OnButtonTestSoundClick )
457
////@end WizardInstrumentsPage event table entries
462
* WizardInstrumentsPage constructors
465
WizardInstrumentsPage::WizardInstrumentsPage( )
469
WizardInstrumentsPage::WizardInstrumentsPage( wxWizard* parent )
478
bool WizardInstrumentsPage::Create( wxWizard* parent )
480
////@begin WizardInstrumentsPage member initialisation
481
m_pVoiceChannelCombo = NULL;
483
m_pInstrCombo = NULL;
484
////@end WizardInstrumentsPage member initialisation
486
////@begin WizardInstrumentsPage creation
487
wxBitmap wizardBitmap(wxNullBitmap);
488
wxWizardPageSimple::Create( parent, NULL, NULL, wizardBitmap );
491
GetSizer()->Fit(this);
492
////@end WizardInstrumentsPage creation
494
// populate channel combo
495
m_pVoiceChannelCombo->Clear();
496
for(int i=1; i <= 16; i++) {
497
m_pVoiceChannelCombo->Append(wxString::Format(_T("%d"), i));
499
//Set selection according to current user prefs
500
m_pVoiceChannelCombo->SetSelection( g_pMidi->VoiceChannel() );
502
//populate sections and instruments combos
503
wxMidiDatabaseGM* pMidiGM = wxMidiDatabaseGM::GetInstance();
504
int nInstr = g_pMidi->VoiceInstr();
505
int nSect = pMidiGM->PopulateWithSections(m_pSectCombo, nInstr );
506
pMidiGM->PopulateWithInstruments(m_pInstrCombo, nSect, nInstr);
512
* Control creation for WizardPage
515
void WizardInstrumentsPage::CreateControls()
517
////@begin WizardInstrumentsPage content construction
518
WizardInstrumentsPage* itemWizardPageSimple16 = this;
520
wxBoxSizer* itemBoxSizer17 = new wxBoxSizer(wxVERTICAL);
521
itemWizardPageSimple16->SetSizer(itemBoxSizer17);
523
wxBoxSizer* itemBoxSizer18 = new wxBoxSizer(wxHORIZONTAL);
524
itemBoxSizer17->Add(itemBoxSizer18, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
526
wxStaticText* itemStaticText19 = new wxStaticText( itemWizardPageSimple16, wxID_STATIC, _("Voice channel and instrument"), wxDefaultPosition, wxDefaultSize, 0 );
527
itemStaticText19->SetFont(wxFont(14, wxSWISS, wxNORMAL, wxBOLD, FALSE, _T("Arial")));
528
itemBoxSizer18->Add(itemStaticText19, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
530
wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxHORIZONTAL);
531
itemBoxSizer17->Add(itemBoxSizer20, 1, wxGROW|wxALL, 5);
533
wxBoxSizer* itemBoxSizer21 = new wxBoxSizer(wxVERTICAL);
534
itemBoxSizer20->Add(itemBoxSizer21, 1, wxGROW|wxALL, 5);
536
wxStaticText* itemStaticText22 = new wxStaticText( itemWizardPageSimple16, wxID_STATIC, _("Channels 10 and 16 are specialized in percussion sounds. So it is recommended to choose any other channel (it doesn't matter wich one)."), wxDefaultPosition, wxSize(250, -1), 0 );
537
itemBoxSizer21->Add(itemStaticText22, 1, wxGROW|wxALL|wxADJUST_MINSIZE, 5);
539
wxStaticText* itemStaticText23 = new wxStaticText( itemWizardPageSimple16, wxID_STATIC, _("To facilitate access to the instruments they are grouped into sections. First choose a section and then choose the desired instrument."), wxDefaultPosition, wxSize(250, -1), 0 );
540
itemBoxSizer21->Add(itemStaticText23, 1, wxGROW|wxALL|wxADJUST_MINSIZE, 5);
542
wxStaticLine* itemStaticLine24 = new wxStaticLine( itemWizardPageSimple16, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL );
543
itemBoxSizer20->Add(itemStaticLine24, 0, wxGROW|wxALL, 5);
545
wxBoxSizer* itemBoxSizer25 = new wxBoxSizer(wxVERTICAL);
546
itemBoxSizer20->Add(itemBoxSizer25, 1, wxGROW|wxALL, 5);
548
wxStaticText* itemStaticText26 = new wxStaticText( itemWizardPageSimple16, wxID_STATIC, _("Channel:"), wxDefaultPosition, wxDefaultSize, 0 );
549
itemBoxSizer25->Add(itemStaticText26, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5);
551
wxString* m_pVoiceChannelComboStrings = NULL;
552
m_pVoiceChannelCombo = new wxComboBox( itemWizardPageSimple16, ID_COMBO_CHANNEL, _T(""), wxDefaultPosition, wxSize(70, -1), 0, m_pVoiceChannelComboStrings, wxCB_DROPDOWN );
553
itemBoxSizer25->Add(m_pVoiceChannelCombo, 0, wxALIGN_LEFT|wxALL, 5);
555
wxBoxSizer* itemBoxSizer28 = new wxBoxSizer(wxVERTICAL);
556
itemBoxSizer25->Add(itemBoxSizer28, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
558
wxStaticText* itemStaticText29 = new wxStaticText( itemWizardPageSimple16, wxID_STATIC, _("Section:"), wxDefaultPosition, wxDefaultSize, 0 );
559
itemBoxSizer25->Add(itemStaticText29, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5);
561
wxString* m_pSectComboStrings = NULL;
562
m_pSectCombo = new wxComboBox( itemWizardPageSimple16, ID_COMBO_SECTION, _T(""), wxDefaultPosition, wxSize(250, -1), 0, m_pSectComboStrings, wxCB_DROPDOWN );
563
itemBoxSizer25->Add(m_pSectCombo, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxBOTTOM, 5);
565
wxStaticText* itemStaticText31 = new wxStaticText( itemWizardPageSimple16, wxID_STATIC, _("lmInstrument:"), wxDefaultPosition, wxDefaultSize, 0 );
566
itemBoxSizer25->Add(itemStaticText31, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5);
568
wxString* m_pInstrComboStrings = NULL;
569
m_pInstrCombo = new wxComboBox( itemWizardPageSimple16, ID_COMBO_INSTRUMENT, _T(""), wxDefaultPosition, wxSize(250, -1), 0, m_pInstrComboStrings, wxCB_DROPDOWN );
570
itemBoxSizer25->Add(m_pInstrCombo, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxBOTTOM, 5);
572
wxButton* itemButton33 = new wxButton( itemWizardPageSimple16, ID_BUTTON_TEST_SOUND, _("Test sound"), wxDefaultPosition, wxDefaultSize, 0 );
573
itemBoxSizer25->Add(itemButton33, 0, wxALIGN_LEFT|wxALL, 5);
575
////@end WizardInstrumentsPage content construction
579
* Should we show tooltips?
582
bool WizardInstrumentsPage::ShowToolTips()
588
* Get bitmap resources
591
wxBitmap WizardInstrumentsPage::GetBitmapResource( const wxString& name )
594
////@begin WizardInstrumentsPage bitmap retrieval
596
////@end WizardInstrumentsPage bitmap retrieval
603
wxIcon WizardInstrumentsPage::GetIconResource( const wxString& name )
606
////@begin WizardInstrumentsPage icon retrieval
608
////@end WizardInstrumentsPage icon retrieval
611
bool WizardInstrumentsPage::TransferDataFromWindow()
614
Save temporary data and set temporary Midi program
622
void WizardInstrumentsPage::DoProgramChange()
624
//Change Midi instrument to the one selected in combo Instruments
625
int nInstr = m_pInstrCombo->GetSelection();
626
int nSect = m_pSectCombo->GetSelection();
627
wxMidiDatabaseGM* pMidiGM = wxMidiDatabaseGM::GetInstance();
628
int nVoiceInstr = pMidiGM->GetInstrFromSection(nSect, nInstr);
629
int nVoiceChannel = m_pVoiceChannelCombo->GetSelection();
630
g_pMidi->VoiceChange(nVoiceChannel, nVoiceInstr);
636
* wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_COMBO_SECTION
639
void WizardInstrumentsPage::OnComboSection( wxCommandEvent& event )
641
// A new section selected. Reload Instruments combo with the instruments in the
644
wxMidiDatabaseGM* pMidiGM = wxMidiDatabaseGM::GetInstance();
645
int nSect = m_pSectCombo->GetSelection();
646
pMidiGM->PopulateWithInstruments(m_pInstrCombo, nSect);
653
* wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_COMBO_INSTRUMENT
656
void WizardInstrumentsPage::OnComboInstrument( wxCommandEvent& event )
658
// A new instrument selected. Change Midi program
664
* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON_TEST_SOUND
667
void WizardInstrumentsPage::OnButtonTestSoundClick( wxCommandEvent& event )
675
* WizardMetronomePage type definition
678
IMPLEMENT_DYNAMIC_CLASS( WizardMetronomePage, wxWizardPageSimple )
681
* WizardMetronomePage event table definition
684
BEGIN_EVENT_TABLE( WizardMetronomePage, wxWizardPageSimple )
686
////@begin WizardMetronomePage event table entries
687
EVT_COMBOBOX( ID_COMBO_MTR_INSTR1, WizardMetronomePage::OnComboMtrInstr1Selected )
689
EVT_COMBOBOX( ID_COMBO_MTR_INSTR2, WizardMetronomePage::OnComboMtrInstr2Selected )
691
EVT_BUTTON( ID_BUTTON, WizardMetronomePage::OnButtonClick )
693
////@end WizardMetronomePage event table entries
698
* WizardMetronomePage constructors
701
WizardMetronomePage::WizardMetronomePage( )
705
WizardMetronomePage::WizardMetronomePage( wxWizard* parent )
711
* WizardMetronomePage creator
714
bool WizardMetronomePage::Create( wxWizard* parent )
716
////@begin WizardMetronomePage member initialisation
717
m_pMtrChannelCombo = NULL;
718
m_pMtrInstr1Combo = NULL;
719
m_pMtrInstr2Combo = NULL;
720
////@end WizardMetronomePage member initialisation
722
////@begin WizardMetronomePage creation
723
wxBitmap wizardBitmap(wxNullBitmap);
724
wxWizardPageSimple::Create( parent, NULL, NULL, wizardBitmap );
727
GetSizer()->Fit(this);
728
////@end WizardMetronomePage creation
730
// populate channel combo
731
m_pMtrChannelCombo->Clear();
732
for(int i=1; i <= 16; i++) {
733
m_pMtrChannelCombo->Append(wxString::Format(_T("%d"), i));
735
//Set selection according to current user prefs
736
m_pMtrChannelCombo->SetSelection( g_pMidi->MtrChannel() );
738
//populate metronome sounds combos
739
wxMidiDatabaseGM* pMidiGM = wxMidiDatabaseGM::GetInstance();
740
int nTone1 = g_pMidi->MtrTone1();
741
int nTone2 = g_pMidi->MtrTone2();
742
pMidiGM->PopulateWithPercusionInstr(m_pMtrInstr1Combo, nTone1);
743
pMidiGM->PopulateWithPercusionInstr(m_pMtrInstr2Combo, nTone2);
749
* Control creation for WizardMetronomePage
752
void WizardMetronomePage::CreateControls()
754
////@begin WizardMetronomePage content construction
755
WizardMetronomePage* itemWizardPageSimple34 = this;
757
wxBoxSizer* itemBoxSizer35 = new wxBoxSizer(wxVERTICAL);
758
itemWizardPageSimple34->SetSizer(itemBoxSizer35);
760
wxBoxSizer* itemBoxSizer36 = new wxBoxSizer(wxHORIZONTAL);
761
itemBoxSizer35->Add(itemBoxSizer36, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
763
wxStaticText* itemStaticText37 = new wxStaticText( itemWizardPageSimple34, wxID_STATIC, _("lmMetronome channel and sounds"), wxDefaultPosition, wxDefaultSize, 0 );
764
itemStaticText37->SetFont(wxFont(14, wxSWISS, wxNORMAL, wxBOLD, FALSE, _T("Arial")));
765
itemBoxSizer36->Add(itemStaticText37, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
767
wxBoxSizer* itemBoxSizer38 = new wxBoxSizer(wxHORIZONTAL);
768
itemBoxSizer35->Add(itemBoxSizer38, 1, wxGROW|wxALL, 5);
770
wxBoxSizer* itemBoxSizer39 = new wxBoxSizer(wxVERTICAL);
771
itemBoxSizer38->Add(itemBoxSizer39, 1, wxGROW|wxALL, 5);
773
wxStaticText* itemStaticText40 = new wxStaticText( itemWizardPageSimple34, wxID_STATIC, _("Channels 10 and 16 are specialized in percussion sounds. So it is recommended to choose one of these (it doesn't matter wich one)."), wxDefaultPosition, wxSize(250, -1), 0 );
774
itemBoxSizer39->Add(itemStaticText40, 1, wxGROW|wxALL|wxADJUST_MINSIZE, 5);
776
wxStaticText* itemStaticText41 = new wxStaticText( itemWizardPageSimple34, wxID_STATIC, _("To better identify the first beat of each measure it is possible to assign a different sound to it. But also you can choose the same sound for both, the first beat and the others."), wxDefaultPosition, wxSize(250, -1), 0 );
777
itemBoxSizer39->Add(itemStaticText41, 1, wxGROW|wxALL|wxADJUST_MINSIZE, 5);
779
wxStaticLine* itemStaticLine42 = new wxStaticLine( itemWizardPageSimple34, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL );
780
itemBoxSizer38->Add(itemStaticLine42, 0, wxGROW|wxALL, 5);
782
wxBoxSizer* itemBoxSizer43 = new wxBoxSizer(wxVERTICAL);
783
itemBoxSizer38->Add(itemBoxSizer43, 1, wxGROW|wxALL, 5);
785
wxStaticText* itemStaticText44 = new wxStaticText( itemWizardPageSimple34, wxID_STATIC, _("Channel:"), wxDefaultPosition, wxDefaultSize, 0 );
786
itemBoxSizer43->Add(itemStaticText44, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5);
788
wxString* m_pMtrChannelComboStrings = NULL;
789
m_pMtrChannelCombo = new wxComboBox( itemWizardPageSimple34, ID_COMBO_MTR_CHANNEL, _T(""), wxDefaultPosition, wxSize(70, -1), 0, m_pMtrChannelComboStrings, wxCB_DROPDOWN );
790
itemBoxSizer43->Add(m_pMtrChannelCombo, 0, wxALIGN_LEFT|wxALL, 5);
792
wxBoxSizer* itemBoxSizer46 = new wxBoxSizer(wxVERTICAL);
793
itemBoxSizer43->Add(itemBoxSizer46, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
795
wxStaticText* itemStaticText47 = new wxStaticText( itemWizardPageSimple34, wxID_STATIC, _("Sound for first beat of each measure:"), wxDefaultPosition, wxDefaultSize, 0 );
796
itemBoxSizer43->Add(itemStaticText47, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5);
798
wxString* m_pMtrInstr1ComboStrings = NULL;
799
m_pMtrInstr1Combo = new wxComboBox( itemWizardPageSimple34, ID_COMBO_MTR_INSTR1, _T(""), wxDefaultPosition, wxSize(250, -1), 0, m_pMtrInstr1ComboStrings, wxCB_DROPDOWN );
800
itemBoxSizer43->Add(m_pMtrInstr1Combo, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxBOTTOM, 5);
802
wxStaticText* itemStaticText49 = new wxStaticText( itemWizardPageSimple34, wxID_STATIC, _("Sound for other beats of each measure:"), wxDefaultPosition, wxDefaultSize, 0 );
803
itemBoxSizer43->Add(itemStaticText49, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP|wxADJUST_MINSIZE, 5);
805
wxString* m_pMtrInstr2ComboStrings = NULL;
806
m_pMtrInstr2Combo = new wxComboBox( itemWizardPageSimple34, ID_COMBO_MTR_INSTR2, _T(""), wxDefaultPosition, wxSize(250, -1), 0, m_pMtrInstr2ComboStrings, wxCB_DROPDOWN );
807
itemBoxSizer43->Add(m_pMtrInstr2Combo, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxBOTTOM, 5);
809
wxButton* itemButton51 = new wxButton( itemWizardPageSimple34, ID_BUTTON, _("Test sound"), wxDefaultPosition, wxDefaultSize, 0 );
810
itemBoxSizer43->Add(itemButton51, 0, wxALIGN_LEFT|wxALL, 5);
812
////@end WizardMetronomePage content construction
816
* Should we show tooltips?
819
bool WizardMetronomePage::ShowToolTips()
825
* Get bitmap resources
828
wxBitmap WizardMetronomePage::GetBitmapResource( const wxString& name )
831
////@begin WizardMetronomePage bitmap retrieval
833
////@end WizardMetronomePage bitmap retrieval
840
wxIcon WizardMetronomePage::GetIconResource( const wxString& name )
843
////@begin WizardMetronomePage icon retrieval
845
////@end WizardMetronomePage icon retrieval
849
* wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_COMBO_MTR_INSTR1
852
void WizardMetronomePage::OnComboMtrInstr1Selected( wxCommandEvent& event )
854
//Change metronome sound, tone1, to the one selected in combo Instr1
855
int nTone1 = m_pMtrInstr1Combo->GetSelection() + 35;
856
g_pMidi->SetMetronomeTones(nTone1, g_pMidi->MtrTone2());
861
* wxEVT_COMMAND_COMBOBOX_SELECTED event handler for ID_COMBO_MTR_INSTR2
864
void WizardMetronomePage::OnComboMtrInstr2Selected( wxCommandEvent& event )
866
//Change metronome sound, tone2, to the one selected in combo Instr2
867
int nTone2 = m_pMtrInstr2Combo->GetSelection() + 35;
868
g_pMidi->SetMetronomeTones(g_pMidi->MtrTone1(), nTone2);
872
* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON
875
void WizardMetronomePage::OnButtonClick( wxCommandEvent& event )
877
if (!g_pMidiOut) return;
879
//two measures, 3/4 time signature
880
for (int i=0; i < 2; i++) {
882
g_pMidiOut->NoteOn(g_pMidi->MtrChannel(), g_pMidi->MtrTone1(), 127);
883
::wxMilliSleep(500); // wait 500ms
884
g_pMidiOut->NoteOff(g_pMidi->MtrChannel(), g_pMidi->MtrTone1(), 127);
886
for (int j=0; j < 2; j++) {
887
g_pMidiOut->NoteOn(g_pMidi->MtrChannel(), g_pMidi->MtrTone2(), 127);
888
::wxMilliSleep(500); // wait 500ms
889
g_pMidiOut->NoteOff(g_pMidi->MtrChannel(), g_pMidi->MtrTone2(), 127);