diff options
-rw-r--r-- | muse2/ChangeLog | 1 | ||||
-rw-r--r-- | muse2/muse/instruments/minstrument.cpp | 60 | ||||
-rw-r--r-- | muse2/muse/instruments/minstrument.h | 15 |
3 files changed, 75 insertions, 1 deletions
diff --git a/muse2/ChangeLog b/muse2/ChangeLog index d8bfa646..8ac5aaea 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,5 +1,6 @@ 23.11.2010 - Added Track::cname(), applied to strip labels' object names, so they may be used in style sheets. (Tim) + - Added struct SysEx and some friends, to minstrument.h, prep. for the instrument editor. (Tim) 22.11.2010 - Oops, fixed regression, marker view and cliplist crashes, removed setAttribute(Qt::WA_DeleteOnClose) from TopWin constructor, and added it to individual TopWin sub-classes (only MidiEditor needs it). (Tim) diff --git a/muse2/muse/instruments/minstrument.cpp b/muse2/muse/instruments/minstrument.cpp index 9bab95be..9f6159dc 100644 --- a/muse2/muse/instruments/minstrument.cpp +++ b/muse2/muse/instruments/minstrument.cpp @@ -26,6 +26,66 @@ MidiInstrument* genericMidiInstrument; static const char* gmdrumname = "GM-drums"; //--------------------------------------------------------- +// string2sysex +//--------------------------------------------------------- + +int string2sysex(const QString& s, unsigned char** data) + { + const char* src = s.toLatin1().data(); + char buffer[2048]; + char* dst = buffer; + + if(src) { + while (*src) { + while (*src == ' ' || *src == '\n') { + ++src; + } + char* ep; + long val = strtol(src, &ep, 16); + if (ep == src) { + QMessageBox::information(0, + QString("MusE"), + QWidget::tr("Cannot convert sysex string")); + return 0; + } + src = ep; + *dst++ = val; + if (dst - buffer >= 2048) { + QMessageBox::information(0, + QString("MusE"), + QWidget::tr("Hex String too long (2048 bytes limit)")); + return 0; + } + } + } + int len = dst - buffer; + unsigned char* b = new unsigned char[len+1]; + memcpy(b, buffer, len); + b[len] = 0; + *data = b; + return len; + } + +//--------------------------------------------------------- +// sysex2string +//--------------------------------------------------------- + +QString sysex2string(int len, unsigned char* data) + { + QString d; + QString s; + for (int i = 0; i < len; ++i) { + if ((i > 0) && ((i % 8)==0)) { + d += "\n"; + } + else if (i) + d += " "; + d += s.sprintf("%02x", data[i]); + } + return d; + } + +//--------------------------------------------------------- // readEventList //--------------------------------------------------------- diff --git a/muse2/muse/instruments/minstrument.h b/muse2/muse/instruments/minstrument.h index dcb0deb9..3e132633 100644 --- a/muse2/muse/instruments/minstrument.h +++ b/muse2/muse/instruments/minstrument.h @@ -14,6 +14,7 @@ #include <vector> #include <QMenu> +#include <QList> class MidiPort; class QMenu; @@ -54,6 +55,13 @@ typedef std::vector<PatchGroup*> PatchGroupList; typedef PatchGroupList::iterator iPatchGroup; typedef PatchGroupList::const_iterator ciPatchGroup; +struct SysEx { + QString name; + QString comment; + int dataLen; + unsigned char* data; + }; + //--------------------------------------------------------- // MidiInstrument //--------------------------------------------------------- @@ -61,6 +69,7 @@ typedef PatchGroupList::const_iterator ciPatchGroup; class MidiInstrument { PatchGroupList pg; MidiControllerList* _controller; + QList<SysEx*> _sysex; bool _dirty; int _nullvalue; @@ -89,7 +98,10 @@ class MidiInstrument { bool dirty() const { return _dirty; } void setDirty(bool v) { _dirty = v; } - + const QList<SysEx*>& sysex() const { return _sysex; } + void removeSysex(SysEx* sysex) { _sysex.removeAll(sysex); } + void addSysex(SysEx* sysex) { _sysex.append(sysex); } + EventList* midiInit() const { return _midiInit; } EventList* midiReset() const { return _midiReset; } EventList* midiState() const { return _midiState; } @@ -109,6 +121,7 @@ class MidiInstrument { virtual void populatePatchPopup(QMenu*, int, MType, bool); void read(Xml&); void write(int level, Xml&); + PatchGroupList* groups() { return &pg; } }; |