summaryrefslogtreecommitdiff
path: root/muse2/muse
diff options
context:
space:
mode:
authorTim E. Real <termtech@rogers.com>2010-11-23 23:30:52 +0000
committerTim E. Real <termtech@rogers.com>2010-11-23 23:30:52 +0000
commit95300fae37761cd68d00b539251dcf0b9023660d (patch)
tree69366146701478b78c220b12514250a65bd3919e /muse2/muse
parentad60c07b70f65bdeab8c0b3bd58bc5421d93f4ab (diff)
Added struct SysEx and some friends, to minstrument.h, prep. for the instrument editor.
Diffstat (limited to 'muse2/muse')
-rw-r--r--muse2/muse/instruments/minstrument.cpp60
-rw-r--r--muse2/muse/instruments/minstrument.h15
2 files changed, 74 insertions, 1 deletions
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; }
};