1
//=========================================================
4
// $Id: minstrument.cpp,v 1.2 2002/02/07 08:14:48 muse Exp $
6
// (C) Copyright 2000 Werner Schweer (ws@seh.de)
7
//=========================================================
9
#include "minstrument.h"
12
#include <qpopupmenu.h>
20
MidiInstrumentList midiInstruments;
21
MidiInstrument* genericMidiInstrument;
23
//---------------------------------------------------------
24
// initMidiInstruments
25
//---------------------------------------------------------
27
void initMidiInstruments()
29
genericMidiInstrument = new MidiInstrument("generic midi");
30
midiInstruments.push_back(genericMidiInstrument);
31
midiInstruments.push_back(new MidiGMInstrument("generic GM"));
32
midiInstruments.push_back(new MidiGSInstrument("generic GS"));
33
midiInstruments.push_back(new MidiXGInstrument("generic XG"));
34
midiInstruments.push_back(new MidiP50mInstrument("Yamaha P50m"));
35
midiInstruments.push_back(new MidiNS5RInstrument("Korg NS5R"));
38
//---------------------------------------------------------
39
// registerMidiInstrument
40
//---------------------------------------------------------
42
MidiInstrument* registerMidiInstrument(const QString& name)
44
for (iMidiInstrument i = midiInstruments.begin();
45
i != midiInstruments.end(); ++i) {
46
if ((*i)->iname() == name)
49
return genericMidiInstrument;
52
//---------------------------------------------------------
53
// removeMidiInstrument
54
//---------------------------------------------------------
56
void removeMidiInstrument(const QString& name)
58
for (iMidiInstrument i = midiInstruments.begin();
59
i != midiInstruments.end(); ++i) {
60
printf("remove Instrument %s\n", name.latin1());
61
midiInstruments.erase(i);
67
EventList* _midiState;
69
//---------------------------------------------------------
71
//---------------------------------------------------------
73
MidiInstrument::MidiInstrument()
75
_midiInit = new EventList();
76
_midiState = new EventList();
79
//---------------------------------------------------------
81
//---------------------------------------------------------
83
MidiInstrument::MidiInstrument(const QString& txt)
86
_midiInit = new EventList();
87
_midiState = new EventList();
90
//---------------------------------------------------------
92
//---------------------------------------------------------
94
MidiInstrument::~MidiInstrument()
100
//---------------------------------------------------------
102
//---------------------------------------------------------
104
const char* MidiInstrument::getPatchName(int, int, int, int, MType)
109
//---------------------------------------------------------
111
//---------------------------------------------------------
113
void MidiGMInstrument::reset(int port, MType)
115
midiPorts[port].gmOn();
118
//---------------------------------------------------------
120
//---------------------------------------------------------
122
const char* MidiGMInstrument::getPatchName(int channel,
123
int, int, int prog, MType)
125
return getPatch(channel, 0, 0, prog, MT_GM);
128
void MidiGMInstrument::populatePatchPopup(QPopupMenu* menu, int, MType)
132
for (int i = 0; i < PROG_GROUPS; ++i) {
133
QPopupMenu* pm = new QPopupMenu(menu);
135
const MidiPatch* mp = patchGroups[i];
138
if (mp->typ & mask) {
139
int id = 0xffff00 + mp->prog;
140
pm->insertItem(mp->name, id);
145
menu->insertItem(gmGroups[i], pm);
149
//---------------------------------------------------------
151
//---------------------------------------------------------
153
void MidiGSInstrument::reset(int port, MType type)
156
midiPorts[port].gmOn();
158
midiPorts[port].gsOn();
161
//---------------------------------------------------------
163
//---------------------------------------------------------
165
const char* MidiGSInstrument::getPatchName(int channel,
166
int hbank, int lbank, int prog, MType)
168
return getPatch(channel, hbank, lbank, prog, MT_GS);
171
void MidiGSInstrument::populatePatchPopup(QPopupMenu* menu, int, MType songType)
176
case MT_GS: mask = 2; break;
179
case MT_UNKNOWN: mask = 1; break;
181
for (int i = 0; i < PROG_GROUPS; ++i) {
182
QPopupMenu* pm = new QPopupMenu(menu);
184
const MidiPatch* mp = patchGroups[i];
187
if (mp->typ & mask) {
188
int id = (mp->hbank<<16) + (mp->lbank<<8) + mp->prog;
189
pm->insertItem(mp->name, id);
194
menu->insertItem(gmGroups[i], pm);
198
//---------------------------------------------------------
200
//---------------------------------------------------------
202
void MidiXGInstrument::reset(int port, MType)
204
midiPorts[port].xgOn();
207
//---------------------------------------------------------
209
//---------------------------------------------------------
211
const char* MidiXGInstrument::getPatchName(int channel,
212
int hbank, int lbank, int prog, MType)
214
return getPatch(channel, hbank, lbank, prog, MT_XG);
217
void MidiXGInstrument::populatePatchPopup(QPopupMenu* menu, int, MType songType)
222
case MT_XG: mask = 4; break;
225
case MT_UNKNOWN: mask = 1; break;
227
for (int i = 0; i < PROG_GROUPS; ++i) {
228
QPopupMenu* pm = new QPopupMenu(menu);
230
const MidiPatch* mp = patchGroups[i];
233
if (mp->typ & mask) {
234
int id = (mp->hbank<<16) + (mp->lbank<<8) + mp->prog;
235
pm->insertItem(mp->name, id);
240
menu->insertItem(gmGroups[i], pm);
244
ProgItem MidiP50mInstrument::progList[29] = {
245
{ "bright piano s+s", 0xffff00 },
246
{ "bright piano s", 0xffff01 },
247
{ "bright piano m+s", 0xffff02 },
248
{ "bright piano m", 0xffff03 },
249
{ "dark piano", 0xffff04 },
250
{ "grand piano s+s", 0xffff05 },
251
{ "grand piano s", 0xffff06 },
252
{ "grand piano m+s", 0xffff07 },
253
{ "grand piano m", 0xffff08 },
254
{ "dance", 0xffff09 },
255
{ "honkytonk", 0xffff0a },
256
{ "hybrid piano", 0xffff0b },
257
{ "cp80, mono", 0xffff0c },
258
{ "cp80, mono s", 0xffff0d },
259
{ "cp80+chorus", 0xffff0e },
260
{ "dx ep", 0xffff0f },
261
{ "dx pad", 0xffff10 },
262
{ "dx ep+chorus", 0xffff11 },
263
{ "roads", 0xffff12 },
264
{ "roads+chorus", 0xffff13 },
265
{ "soft roads", 0xffff14 },
266
{ "hard roads", 0xffff15 },
267
{ "dyno", 0xffff16 },
268
{ "resonant dyno", 0xffff17 },
269
{ "dyno+chorus", 0xffff18 },
270
{ "wurli", 0xffff19 },
271
{ "clavi", 0xffff1a },
272
{ "clavi+wah", 0xffff1b },
273
{ "no sound", 0xffff1c },
276
//---------------------------------------------------------
278
//---------------------------------------------------------
280
void MidiP50mInstrument::reset(int port, MType)
282
midiPorts[port].gmOn();
285
//---------------------------------------------------------
287
//---------------------------------------------------------
289
const char* MidiP50mInstrument::getPatchName(int, int, int, int prog, MType)
291
int nprogs = sizeof(progList)/sizeof(*progList);
294
return progList[prog].name;
297
void MidiP50mInstrument::populatePatchPopup(QPopupMenu* menu, int, MType)
300
int nprogs = sizeof(progList)/sizeof(*progList);
301
for (int i = 0; i < nprogs; ++i)
302
menu->insertItem(progList[i].name, progList[i].id);
305
//---------------------------------------------------------
307
// the Korg NS5R is GM/GS/XG compatible
308
//---------------------------------------------------------
310
void MidiNS5RInstrument::reset(int port, MType _mode)
316
midiPorts[port].xgOn();
319
midiPorts[port].gsOn();
322
midiPorts[port].gmOn();
327
//---------------------------------------------------------
328
// MidiNS5R::getPatchName
329
//---------------------------------------------------------
331
const char* MidiNS5RInstrument::getPatchName(int channel,
332
int hbank, int lbank, int prog, MType mode)
334
return getPatch(channel, hbank, lbank, prog, mode);
337
//---------------------------------------------------------
338
// MidiNS5R::populatePatchPopup
339
//---------------------------------------------------------
341
void MidiNS5RInstrument::populatePatchPopup(QPopupMenu* menu, int, MType songType)
346
case MT_XG: mask = 4; break;
347
case MT_GS: mask = 2; break;
349
case MT_UNKNOWN: mask = 1; break;
351
for (int i = 0; i < PROG_GROUPS; ++i) {
352
QPopupMenu* pm = new QPopupMenu(menu);
354
const MidiPatch* mp = patchGroups[i];
357
if (mp->typ & mask) {
358
int id = (mp->hbank<<16) + (mp->lbank<<8) + mp->prog;
359
pm->insertItem(mp->name, id);
364
menu->insertItem(gmGroups[i], pm);
368
//---------------------------------------------------------
370
//---------------------------------------------------------
372
void MidiInstrument::readMidiState(Xml& xml)
375
Xml::Token token = xml.parse();
376
const QString& tag = xml.s1();
382
if (tag == "event") {
383
Event* e = new MidiEvent();
388
xml.unknown("readMidiState");
391
if (tag == "midistate")
399
//---------------------------------------------------------
401
//---------------------------------------------------------
403
void MidiInstrument::readMidiInit(Xml& xml)
406
Xml::Token token = xml.parse();
407
const QString& tag = xml.s1();
413
if (tag == "event") {
414
Event* e = new MidiEvent();
419
xml.unknown("readMidiInit");
422
if (tag == "midiinit")