1
/***************************************************************************
2
* KMidimon - ALSA sequencer based MIDI monitor *
3
* Copyright (C) 2005-2009 Pedro Lopez-Cabanillas *
4
* plcl@users.sourceforge.net *
6
* For this file, the following copyright notice is also applicable: *
7
* Copyright (C) 2005-2009, rncbc aka Rui Nuno Capela. All rights reserved.*
8
* See http://qtractor.sourceforge.net *
10
* This program is free software; you can redistribute it and/or modify *
11
* it under the terms of the GNU General Public License as published by *
12
* the Free Software Foundation; either version 2 of the License, or *
13
* (at your option) any later version. *
15
* This program is distributed in the hope that it will be useful, *
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18
* GNU General Public License for more details. *
20
* You should have received a copy of the GNU General Public License *
21
* along with this program; if not, write to the Free Software *
22
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, *
23
* MA 02110-1301, USA *
24
***************************************************************************/
26
/* Library of compatible instrument definitions:
27
ftp://ftp.cakewalk.com/pub/InstrumentDefinitions/ */
29
#ifndef __instrument_h
30
#define __instrument_h
32
#include <QStringList>
35
// Forward declarations.
38
//----------------------------------------------------------------------
39
// class InstrumentData -- instrument definition data classes.
46
typedef QMap<int, QString> DataMap;
50
: m_pData(new DataRef()) {}
52
InstrumentData(const InstrumentData& data)
58
// Assignment operator.
59
InstrumentData& operator= (const InstrumentData& data)
61
if (m_pData != data.m_pData) {
69
QString& operator[] (int iIndex) const
70
{ return m_pData->map[iIndex]; }
72
// Property accessors.
73
void setName(const QString& sName)
74
{ m_pData->name = sName; }
75
const QString& name() const { return m_pData->name; }
77
void setBasedOn(const QString& sBasedOn)
78
{ m_pData->basedOn = sBasedOn; }
79
const QString& basedOn() const { return m_pData->basedOn; }
81
// Indirect iterator stuff.
82
typedef DataMap::Iterator Iterator;
83
Iterator begin() { return m_pData->map.begin(); }
84
Iterator end() { return m_pData->map.end(); }
86
typedef DataMap::ConstIterator ConstIterator;
87
ConstIterator begin() const { return m_pData->map.constBegin(); }
88
ConstIterator end() const { return m_pData->map.constEnd(); }
90
unsigned int count() const { return m_pData->map.count(); }
92
bool contains(int iKey) const
93
{ return m_pData->map.contains(iKey); }
98
void attach(const InstrumentData& data)
99
{ m_pData = data.m_pData; m_pData->refCount++; }
102
{ if (--(m_pData->refCount) == 0) delete m_pData; }
106
// The ref-counted data.
109
// Default payload constructor.
110
DataRef() : refCount(1) {};
120
class InstrumentDataList
121
: public QMap<QString, InstrumentData> {};
123
class InstrumentPatches
124
: public QMap<int, InstrumentData> {};
126
class InstrumentNotes
127
: public QMap<int, InstrumentData> {};
130
: public QMap<int, InstrumentNotes> {};
132
class InstrumentDrumFlags
133
: public QMap<int, int> {};
135
class InstrumentDrums
136
: public QMap<int, InstrumentDrumFlags> {};
139
//----------------------------------------------------------------------
140
// class Instrument -- instrument definition instance class.
149
: m_pData(new DataRef()) {}
151
Instrument(const Instrument& instr)
157
// Assignment operator.
158
Instrument& operator= (const Instrument& instr)
160
if (m_pData != instr.m_pData) {
167
// Instrument title property accessors.
168
void setInstrumentName(const QString& sInstrumentName)
169
{ m_pData->instrumentName = sInstrumentName; }
170
const QString& instrumentName() const
171
{ return m_pData->instrumentName; }
173
// BankSelMethod accessors.
174
void setBankSelMethod(int iBankSelMethod)
175
{ m_pData->bankSelMethod = iBankSelMethod; }
176
int bankSelMethod() const { return m_pData->bankSelMethod; }
178
void setUsesNotesAsControllers(bool bUsesNotesAsControllers)
179
{ m_pData->usesNotesAsControllers = bUsesNotesAsControllers; }
180
bool usesNotesAsControllers() const
181
{ return m_pData->usesNotesAsControllers; }
183
// Patch banks accessors.
184
const InstrumentPatches& patches() const
185
{ return m_pData->patches; }
186
const InstrumentData& patch(int iBank) const;
187
void setPatch(int iBank, const InstrumentData& patch)
188
{ m_pData->patches[iBank] = patch; }
190
// Control names accessors.
191
void setControlName(const QString& sControlName)
192
{ m_pData->control.setName(sControlName); }
193
const QString& controlName() const
194
{ return m_pData->control.name(); }
195
void setControl(const InstrumentData& control)
196
{ m_pData->control = control; }
197
const InstrumentData& control() const
198
{ return m_pData->control; }
200
// RPN names accessors.
201
void setRpnName(const QString& sRpnName)
202
{ m_pData->rpn.setName(sRpnName); }
203
const QString& rpnName() const
204
{ return m_pData->rpn.name(); }
205
void setRpn(const InstrumentData& rpn)
206
{ m_pData->rpn = rpn; }
207
const InstrumentData& rpn() const
208
{ return m_pData->rpn; }
210
// NRPN names accessors.
211
void setNrpnName(const QString& sNrpnName)
212
{ m_pData->nrpn.setName(sNrpnName); }
213
const QString& nrpnName() const
214
{ return m_pData->nrpn.name(); }
215
void setNrpn(const InstrumentData& nrpn)
216
{ m_pData->nrpn = nrpn; }
217
const InstrumentData& nrpn() const
218
{ return m_pData->nrpn; }
220
// Keys banks accessors.
221
const InstrumentData& notes(int iBank, int iProg) const;
222
void setNotes(int iBank, int iProg, const InstrumentData& notes)
223
{ m_pData->keys[iBank][iProg] = notes; }
224
const InstrumentKeys& keys() const
225
{ return m_pData->keys; }
227
// Drumflags banks accessors.
228
bool isDrum(int iBank, int iProg) const;
229
void setDrum(int iBank, int iProg, bool bDrum)
230
{ m_pData->drums[iBank][iProg] = (int) bDrum; }
231
const InstrumentDrums& drums() const
232
{ return m_pData->drums; }
236
// Copy/clone method.
237
void attach(const Instrument& instr)
238
{ m_pData = instr.m_pData; m_pData->refCount++; }
241
{ if (--(m_pData->refCount) == 0) delete m_pData; }
245
// The ref-counted data.
248
// Default payload constructor.
249
DataRef() : refCount(1),
250
bankSelMethod(0), usesNotesAsControllers(false) {};
254
bool usesNotesAsControllers;
255
QString instrumentName;
256
InstrumentPatches patches;
257
InstrumentData control;
261
InstrumentDrums drums;
267
//----------------------------------------------------------------------
268
// class InstrumentList -- A Cakewalk .ins file container class.
271
class InstrumentList : public QMap<QString, Instrument>
275
// Open file methods.
276
bool load(const QString& sFilename);
277
bool save(const QString& sFilename);
279
// The official loaded file list.
280
const QStringList& files() const;
282
// Manage a file list (out of sync)
283
void appendFile(const QString& sFilename)
284
{ m_files.append(sFilename); }
285
void removeFile(const QString& sFilename)
287
int iFile = m_files.indexOf(sFilename);
289
m_files.removeAt(iFile);
292
// Patch Names definition accessors.
293
const InstrumentDataList& patches() const
294
{ return m_patches; }
295
const InstrumentData& patch(const QString& sName)
296
{ return m_patches[sName]; }
298
// Note Names definition accessors.
299
const InstrumentDataList& notes() const
301
InstrumentData& note(const QString& sName)
302
{ return m_notes[sName]; }
304
// Controller Names definition accessors.
305
const InstrumentDataList& controllers() const
306
{ return m_controllers; }
307
InstrumentData& controller(const QString& sName)
308
{ return m_controllers[sName]; }
310
// RPN Names definition accessors.
311
const InstrumentDataList& rpns() const
313
InstrumentData& rpn(const QString& sName)
314
{ return m_rpns[sName]; }
316
// NRPN Names definition accessors.
317
const InstrumentDataList& nrpns() const
319
InstrumentData& nrpn(const QString& sName)
320
{ return m_nrpns[sName]; }
322
// Clear all contents.
325
// Special instrument list merge method.
326
void merge(const InstrumentList& instruments);
330
// Internal instrument data list save method helpers.
331
void saveDataList(QTextStream& ts, const InstrumentDataList& list);
332
void saveData(QTextStream& ts, const InstrumentData& data);
334
// Special instrument data list merge method.
335
void mergeDataList(InstrumentDataList& dst,
336
const InstrumentDataList& src);
340
// To hold the names definition lists.
341
InstrumentDataList m_patches;
342
InstrumentDataList m_notes;
343
InstrumentDataList m_controllers;
344
InstrumentDataList m_rpns;
345
InstrumentDataList m_nrpns;
347
// To old the official file list.
352
#endif // __instrument_h