00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef TSE3_INS_INSTRUMENT_H
00018 #define TSE3_INS_INSTRUMENT_H
00019
00020 #include <list>
00021 #include <utility>
00022 #include <vector>
00023 #include <string>
00024 #include <iosfwd>
00025
00026 namespace TSE3
00027 {
00028 class Progress;
00029
00052 namespace Ins
00053 {
00054 class PatchData;
00055 class ControlData;
00056 class RpnData;
00057 class NrpnData;
00058 class NoteData;
00059
00073 inline int bankToLSB(int bank)
00074 {
00075 return (bank < 0) ? bank : bank & 0x7f;
00076 }
00077
00091 inline int bankToMSB(int bank)
00092 {
00093 return (bank < 0) ? bank : bank >> 7;
00094 }
00095
00110 inline int bankFromBytes(int bankLSB, int bankMSB)
00111 {
00112 return (bankLSB < 0 || bankMSB < 0) ? -1 : (bankMSB<<7) | bankLSB;
00113 }
00114
00130 struct Voice : public std::pair<int, int>
00131 {
00138 Voice(int bank, int patch);
00139
00147 Voice(int bankMSB, int bankLSB, int patch);
00148
00152 int bank() const { return first; }
00153
00157 int bankMSB() const { return first >> 7; }
00158
00162 int bankLSB() const { return first & 0x7f; }
00163
00167 int patch() const { return second; }
00168
00172 int operator <(const Voice &v) const;
00173 };
00174
00187 class Instrument
00188 {
00189 public:
00190
00204 Instrument(const std::string &title,
00205 const std::string &filename,
00206 TSE3::Progress *progess = 0);
00207
00213 const std::string &title() const { return _title; }
00214
00221 const std::string &filename() const { return _filename; }
00222
00228 void setTitle(const std::string &title);
00229
00236 int bankSelMethod() const { return _bankSelMethod; }
00237
00243 void setBankSelMethod(int b);
00244
00257 enum BankSelMethod
00258 {
00259 BankSelMethod_Normal = 0,
00260 BankSelMethod_MSB = 1,
00261 BankSelMethod_LSB = 2,
00262 BankSelMethod_Patch = 3
00263 };
00264
00270 bool useNotesAsController() const
00271 {
00272 return _useNotesAsControllers;
00273 }
00274
00280 void setUseNotesAsControllers(bool u);
00281
00288 size_t numBanks() const { return banks.size(); }
00289
00302 int bank(int index) const { return banks[index]; }
00303
00314 int bank(const Voice &voice) const;
00315
00326 int bankLSB(int index) const;
00327
00338 int bankMSB(int index) const;
00339
00346 PatchData *patch(int index) const { return patches[index]; }
00347
00365 PatchData *patchForBank(int bank) const;
00366
00380 PatchData *patchForBank(int bankLSB, int bankMSB) const;
00381
00388 size_t numKeys() const { return keys.size(); }
00389
00398 NoteData *key(size_t index) const { return keys[index].second; }
00399
00407 NoteData *keyForVoice(const Voice &voice) const;
00408
00415 size_t numDrums() const { return drumFlags.size(); }
00416
00425 Voice drum(size_t index) const { return drumFlags[index]; }
00426
00434 bool isDrum(const Voice &voice) const;
00435
00442 ControlData *control() const { return _control; }
00443
00450 RpnData *rpn() const { return _rpn; }
00451
00458 NrpnData *nrpn() const { return _nrpn; }
00459
00465 void write(std::ostream &out);
00466
00467 private:
00468
00474 void load(std::istream &in, TSE3::Progress *progress);
00475
00481 void parseLine(const std::string &line, std::istream &in);
00482
00483 std::string _title;
00484 std::string _filename;
00485 int _bankSelMethod;
00486 bool _useNotesAsControllers;
00487
00488 std::vector<PatchData *> patches;
00489 std::vector<int> banks;
00490
00491 std::vector<std::pair<Voice, NoteData *> > keys;
00492 std::vector<Voice> drumFlags;
00493
00494 ControlData *_control;
00495 RpnData *_rpn;
00496 NrpnData *_nrpn;
00497 };
00498
00508 class InstrumentData
00509 {
00510 public:
00511
00517 const std::string &title() const { return _title; }
00518
00529 const std::string &name(size_t index) const
00530 {
00531 std::string *s = _names[index];
00532 return s ? *s : empty;
00533 }
00534
00540 void write(std::ostream &out) const;
00541
00542 protected:
00543
00547 InstrumentData(std::string const &title,
00548 std::string const &insHeading,
00549 std::istream &in);
00550
00557 const std::string insHeading;
00558
00564 void load(const std::string &secname, std::istream &in);
00565
00566 std::string _title;
00567 std::string *_names[128];
00568
00569 static std::string empty;
00570 };
00571
00580 class PatchData : public InstrumentData
00581 {
00582 public:
00583 PatchData(std::string const &title, std::istream &in)
00584 : InstrumentData(title, ".Patch Names", in) {}
00585 };
00586
00594 class NoteData : public InstrumentData
00595 {
00596 public:
00597 NoteData(std::string const &title, std::istream &in)
00598 : InstrumentData(title, ".Note Names", in) {}
00599 };
00600
00608 class ControlData : public InstrumentData
00609 {
00610 public:
00611 ControlData(std::string const &title, std::istream &in)
00612 : InstrumentData(title, ".Controller Names", in) {}
00613 };
00614
00622 class NrpnData : public InstrumentData
00623 {
00624 public:
00625 NrpnData(std::string const &title, std::istream &in)
00626 : InstrumentData(title, ".NRPN Names", in) {}
00627 };
00628
00636 class RpnData : public InstrumentData
00637 {
00638 public:
00639 RpnData(std::string const &title, std::istream &in)
00640 : InstrumentData(title, ".RPN Names", in) {}
00641 };
00642
00658 class CakewalkInstrumentFile
00659 {
00660 public:
00661
00667 CakewalkInstrumentFile(const std::string &filename);
00668
00680 const std::list<std::string>
00681 &instruments(TSE3::Progress *progress = 0);
00682
00695 Instrument *instrument(const std::string &title,
00696 TSE3::Progress *progress = 0);
00697
00698 private:
00699
00700 std::string filename;
00701 bool searched_yet;
00702 std::list<std::string> ins;
00703 };
00704 }
00705 }
00706
00707 #endif