wxMidi - A MIDI interface based on PortMidi
wxMidiDatabaseGM Class Reference

A database for Midi GM (General MIDI Standard) instruments. More...

#include <wxMidi.h>

Public Member Functions

void PopulateWithInstruments (wxControlWithItems *pCtrol, int nSection, int nInstr=0, bool fAddNumber=false)
 Load control pCtrol with the list of all instruments that belong to section nSection . More...
 
void PopulateWithPercusionInstr (wxControlWithItems *pCtrol, int iSel=0)
 In the MIDI standard channel 9 is reserved for "key-based" percussion sounds. More...
 
int PopulateWithSections (wxControlWithItems *pCtrol, int nSelInstr=-1)
 Load control pCtrol with the list of all sections in which the instruments in the GM standard have been organized in the wxMidiDatabaseGM. More...
 
void PopulateWithAllInstruments (wxControlWithItems *pCtrol, int nInstr=0)
 Load control pCtrol with the list of all instrumens in the GM standard. More...
 
int GetNumSections ()
 Returns the number of sections in which the instruments in the GM standard has been organized. More...
 
int GetNumInstrumentsInSection (int nSect)
 Returns the number of instruments that are included in section number nSect. More...
 
int GetInstrFromSection (int nSect, int i)
 Returns the GM number of the n th instrument in section nSect. More...
 
wxString GetInstrumentName (int nInstr)
 Returns a string with the name of instrument nInstr. More...
 
wxString GetSectionName (int nSect)
 Returns a string containig the name of section number nSect. More...
 

Static Public Member Functions

static wxMidiDatabaseGMGetInstance ()
 Returns a pointer to the only wxMidiDatabaseGM instance. More...
 

Detailed Description

A database for Midi GM (General MIDI Standard) instruments.

See A database for MIDI (General MIDI Standard) instruments for details

Member Function Documentation

◆ GetInstance()

wxMidiDatabaseGM * wxMidiDatabaseGM::GetInstance ( )
static

Returns a pointer to the only wxMidiDatabaseGM instance.

Note that wxMidiDatabaseGM is a singleton and, therefore, the constructor is not public. Access to the only instance must be through this GetInstance() method.

◆ GetInstrFromSection()

int wxMidiDatabaseGM::GetInstrFromSection ( int  nSect,
int  i 
)

Returns the GM number of the n th instrument in section nSect.

Parameters
nSectThe number of the section in which it is included the instrument to retrieve. Must be a number in the range 0 to wxMidiDatabaseGM::GetNumSections() - 1.
iThe position (0 to GetNumInstrumentsInSection() - 1 ) in section of the instrument whose GM index is desired. Remarks: This method is useful when in your application, the instruments are presented organized into sections instead of in a single list with all GM instruments. In the first case, when the user selects an instrument, it is necessary to translate the pair (section number, instrument number - relative to section -) to the GM standard program number, as in following example:
// It is assumed that combo box <I>m_pSectCombo</I> is loaded
// with section names and that combo box <I>m_pInstrCombo</I>
// is loaded with the names of the instruments
// in the selected section.
void MyFrame::OnComboInstruments(wxCommandEvent &event)
{
// A new instrument has been selected. Change Midi program
int nInstr = m_pInstrCombo->GetSelection();
int nSect = m_pSectCombo->GetSelection();
int nProgram = pMidiGM->GetInstrFromSection(nSect, nInstr);
int nChannel = m_channel;
wxMidiError nErr = m_pOutDev->ProgramChange(nChannel, nProgram);
if (nErr) {
...
}
else {
...
}
}

◆ GetInstrumentName()

wxString wxMidiDatabaseGM::GetInstrumentName ( int  nInstr)

Returns a string with the name of instrument nInstr.

Parameters
nInstrThe number (0 to 127, according the GM standard) whose name is to be retrieved.

Remarks: To populate a control (i.e. a combo box) with the names of all instruments you can do it in a single call by using method PopulateWithAllInstruments() instead of doing it inside a loop of calls to GetInstrumentName().

See also
PopulateWithAllInstruments, PopulateWithInstruments, PopulateWithPercusionInstr

◆ GetNumInstrumentsInSection()

int wxMidiDatabaseGM::GetNumInstrumentsInSection ( int  nSect)

Returns the number of instruments that are included in section number nSect.

In the wxMidiDatabaseGM, the number of instruments in a section is always eight. This method was included to allow for future extensions and to deal with other MIDI standards.

Parameters
nSectThe number of the section for which the number of instruments in it is desired. Must be a number in the range 0 to wxMidiDatabaseGM::GetNumSections() - 1.
See also
GetInstrFromSection, GetNumSections, GetSectionName, PopulateWithInstruments

◆ GetNumSections()

int wxMidiDatabaseGM::GetNumSections ( )

Returns the number of sections in which the instruments in the GM standard has been organized.

In the wxMidiDatabaseGM, the number sections is always 16. This method was included to allow for future extensions and to deal with other MIDI standards.

See also
GetNumInstrumentsInSection, GetSectionName, PopulateWithSections

◆ GetSectionName()

wxString wxMidiDatabaseGM::GetSectionName ( int  nSect)

Returns a string containig the name of section number nSect.

Parameters
nSectThe number of the section whose name is desired. Must be a number in range 0 to wxMidiDatabaseGM::GetNumSections() - 1.

Remarks: To populate a control (i.e. a combo box) with the names of all sections you can do it in a single call by using method PopulateWithSections() instead of doing it inside a loop of calls to GetSectionName().

See also
GetInstrFromSection, GetNumInstrumentsInSection, GetNumSections, PopulateWithSections

◆ PopulateWithAllInstruments()

void wxMidiDatabaseGM::PopulateWithAllInstruments ( wxControlWithItems *  pCtrol,
int  nInstr = 0 
)

Load control pCtrol with the list of all instrumens in the GM standard.

If nInstr is specified, the name of that instrument is left selected in the control. Otherwise, the first instrument is left selected.

Parameters
pCtrolPointer to wxControlWithItems object to be initialized and populated.
nInstrNumber (0 to 127) of the instrument to select.

Example:

pInstrCombo =
new wxComboBox(panel, ID_COMBO_INSTRUMENTS,
_T("This"),
wxPoint(20,25), wxSize(270, wxDefaultCoord),
0, NULL,
wxCB_DROPDOWN | wxCB_READONLY | wxPROCESS_ENTER);
pMidiGM->PopulateWithAllInstruments(pInstrCombo);
See also
PopulateWithSections, PopulateWithInstruments, PopulateWithPercusionInstr

◆ PopulateWithInstruments()

void wxMidiDatabaseGM::PopulateWithInstruments ( wxControlWithItems *  pCtrol,
int  nSection,
int  nInstr = 0,
bool  fAddNumber = false 
)

Load control pCtrol with the list of all instruments that belong to section nSection .

If nInstr is specified, the name of that instrument is left selected in the control. Otherwise, the first instrument of the section is left selected.

Parameters
pCtrolPointer to wxControlWithItems object to be initialized and populated.
nSectionThe number of the section whose instruments' names are going to be loaded. Must be a number in range 0 to wxMidiDatabaseGM::GetNumSections() - 1.
nInstrNumber (0 to GetNumInstrumentsInSection() - 1 ) of the instrument to select.
fAddNumberWhen TRUE, instrument number is included in the strings loaded in in the control, i.e. "37 - Side Stick". Otherwise, if FALSE, only the instrument name is generated, i.e. "Side Stick".

Remarks: This method is useful when in your application, the instruments are presented organized into sections instead of in a single long list with all GM instruments. For example, you have to load a combo box with the list of all sections and other combo box with the list of instruments in currently selected section, as in following example:

MyFrame::MyFrame (...)
{
...
m_pSectCombo =
new wxComboBox(this, ID_COMBO_SECTIONS,
_T("This"),
wxPoint(20,25), wxSize(270, wxDefaultCoord),
0, NULL,
wxCB_DROPDOWN | wxCB_READONLY | wxPROCESS_ENTER);
pMidiGM->PopulateWithSections(m_pSectCombo);
m_pInstrCombo =
new wxComboBox(this, ID_COMBO_INSTRUMENTS,
_T("This"),
wxPoint(20,25), wxSize(270, wxDefaultCoord),
0, NULL,
wxCB_DROPDOWN | wxCB_READONLY | wxPROCESS_ENTER);
pMidiGM->PopulateWithInstruments(m_pInstrCombo, 0, 0);
...
}
void MyFrame::OnComboSections(wxCommandEvent &event)
{
// A new section selected. Reload Instruments combo
// with the instruments in the selected section
int nSect = m_pSectCombo->GetSelection();
pMidiGM->PopulateWithInstruments(m_pInstrCombo, nSect);
DoProgramChange();
}
void MyFrame::OnComboInstruments(wxCommandEvent &event)
{
// A new instrument selected. Change Midi program
DoProgramChange();
}
void MyFrame::DoProgramChange()
{
// A new instrument has been selected. Change Midi program
int nInstr = m_pInstrCombo->GetSelection();
int nSect = m_pSectCombo->GetSelection();
int nProgram = pMidiGM->GetInstrFromSection(nSect, nInstr);
int nChannel = m_channel;
wxMidiError nErr = m_pOutDev->ProgramChange(nChannel, nProgram);
if (nErr) {
...
}
else {
...
}
}
See also
PopulateWithAllInstruments, PopulateWithPercusionInstr, PopulateWithSections

◆ PopulateWithPercusionInstr()

void wxMidiDatabaseGM::PopulateWithPercusionInstr ( wxControlWithItems *  pCtrol,
int  iSel = 0 
)

In the MIDI standard channel 9 is reserved for "key-based" percussion sounds.

For these "key-based" sounds, the note number data in a NoteOn message is used to select which drum sound will be played. For example, a NoteOn message on channel 9 with note number 60 will play a Hi Bongo drum sound. Note number 59 on channel 9 will play the Ride Cymbal 2 sound. Method PopulateWithPercusionInstr() is used to load a control (combo box, list box, or other derived from wxControlWithItems) whit the list of all key-based percussion sounds in the GM standard.

Parameters
pCtrolPointer to wxControlWithItems object to be initialized and populated.
iSelNumber (35 to 81) of the sound to leave selected in the control. Default value (zero) is for leaving selected the first available sound (35-Acoustic Bass Drum) as well as any out of range value.

The list of percussion sounds in the GM standard is included here for your conveniece:

iSelInstrument iSelInstrument
35 Acoustic Bass Drum 59 Ride Cymbal 2
36 Bass Drum 1 60 High Bongo
37 Side Stick 61 Low Bongo
38 Acoustic Snare 62 Mute High Conga
39 Hand clap 63 Open High Conga
40 Electric Snare 64 Low Conga
41 Low Floor Tom 65 High Timbale
42 Closed High-Hat 66 Low Timbale
43 High Floor Tom 67 High Agogo
44 Pedal High-Hat 68 Low Agogo
45 Low Tom 69 Casaba
46 Open High-Hat 70 Maracas
47 Low-Mid Tom 71 Short Whistle
48 High-Mid Tom 72 Long Whistle
49 Crash Cymbal 1 73 Short Guiro
50 High Tom 74 Long Guiro
51 Ride Cymbal 1 75 Claves
52 Chinese Cymbal 76 High Wood Block
53 Ride Bell 77 Low Wood Block
54 Tambourine 78 Mute Cuica
55 Splash Cymbal 79 Open Cuica
56 Cowbell 80 Mute Triangle
57 Crash Cymbal 2 81 Open Triangle
58 Vibraslap

◆ PopulateWithSections()

int wxMidiDatabaseGM::PopulateWithSections ( wxControlWithItems *  pCtrol,
int  nSelInstr = -1 
)

Load control pCtrol with the list of all sections in which the instruments in the GM standard have been organized in the wxMidiDatabaseGM.

If nSelInstr is specified, the name of that section is left selected in the control. Otherwise, the first section is left selected.

Parameters
pCtrolPointer to wxControlWithItems object to be initialized and populated.
nSelInstrNumber (0 to GetNumSections() - 1 ) of the section to select.

Remarks: This method is useful when in your application, the instruments are presented organized into sections instead of in a single long list with all GM instruments. See an example in method PopulateWithInstruments().

See also
PopulateWithAllInstruments, PopulateWithPercusionInstr, PopulateWithInstruments

The documentation for this class was generated from the following files: