From efeadeaabeb1a0ec25c8299b14465eb3ed6d3ded Mon Sep 17 00:00:00 2001 From: Werner Schweer Date: Mon, 23 Oct 2006 12:41:54 +0000 Subject: rename midievent to midieventbase --- muse/muse/event.cpp | 2 +- muse/muse/exportmidi.cpp | 2 +- muse/muse/instruments/minstrument.cpp | 2 +- muse/muse/midievent.cpp | 163 ---------------------------------- muse/muse/midievent.h | 118 ++++++++++++++++++++++++ muse/muse/midieventbase.cpp | 163 ++++++++++++++++++++++++++++++++++ muse/muse/midifile.cpp | 2 +- muse/muse/mpevent.cpp | 2 +- muse/muse/mpevent.h | 118 ------------------------ muse/muse/synth.cpp | 2 +- 10 files changed, 287 insertions(+), 287 deletions(-) delete mode 100644 muse/muse/midievent.cpp create mode 100644 muse/muse/midievent.h create mode 100644 muse/muse/midieventbase.cpp delete mode 100644 muse/muse/mpevent.h diff --git a/muse/muse/event.cpp b/muse/muse/event.cpp index e7c529cd..77438764 100644 --- a/muse/muse/event.cpp +++ b/muse/muse/event.cpp @@ -21,7 +21,7 @@ #include "event.h" #include "eventbase.h" #include "waveevent.h" -#include "midievent.h" +#include "midieventbase.h" using AL::Pos; diff --git a/muse/muse/exportmidi.cpp b/muse/muse/exportmidi.cpp index 86592a68..94838d4e 100644 --- a/muse/muse/exportmidi.cpp +++ b/muse/muse/exportmidi.cpp @@ -25,7 +25,7 @@ #include "globals.h" #include "widgets/filedialog.h" #include "song.h" -#include "mpevent.h" +#include "midievent.h" #include "event.h" #include "midiedit/drummap.h" #include "gconfig.h" diff --git a/muse/muse/instruments/minstrument.cpp b/muse/muse/instruments/minstrument.cpp index ce1bcdd7..b69cd1f3 100644 --- a/muse/muse/instruments/minstrument.cpp +++ b/muse/muse/instruments/minstrument.cpp @@ -22,7 +22,7 @@ #include "midioutport.h" #include "globals.h" #include "event.h" -#include "mpevent.h" +#include "midievent.h" #include "midictrl.h" #include "gconfig.h" #include "midiedit/drummap.h" diff --git a/muse/muse/midievent.cpp b/muse/muse/midievent.cpp deleted file mode 100644 index bdf97af4..00000000 --- a/muse/muse/midievent.cpp +++ /dev/null @@ -1,163 +0,0 @@ -//============================================================================= -// MusE -// Linux Music Editor -// $Id:$ -// -// Copyright (C) 2002-2006 by Werner Schweer and others -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License version 2. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -//============================================================================= - -#include "event.h" -#include "midievent.h" -#include "al/xml.h" -#include "mpevent.h" -#include "midictrl.h" -#include "muse.h" - -//--------------------------------------------------------- -// MidiEventBase -//--------------------------------------------------------- - -MidiEventBase::MidiEventBase(EventType t) - : EventBase(t) - { - a = 0; - b = 0; - c = 0; - } - -//--------------------------------------------------------- -// MidiEventBase::mid -//--------------------------------------------------------- - -EventBase* MidiEventBase::mid(unsigned b, unsigned e) - { - if (tick() < b || tick() >= e) - return 0; - return new MidiEventBase(*this); - } - -//--------------------------------------------------------- -// isNoteOff -//--------------------------------------------------------- - -bool MidiEventBase::isNoteOff() const - { - return (type() == Note && (velo() == 0)); - } - -bool MidiEventBase::isNoteOff(const Event& e) const - { - return (e.isNoteOff() && (e.pitch() == a)); - } - -void MidiEventBase::dump(int n) const - { - EventBase::dump(n); - char* p; - - switch(type()) { - case Note: p = "Note "; break; - case Controller: p = "Ctrl "; break; - case Sysex: p = "Sysex "; break; - case PAfter: p = "PAfter "; break; - case CAfter: p = "CAfter "; break; - case Meta: p = "Meta "; break; - default: p = "?? "; break; - } - for (int i = 0; i < (n+2); ++i) - putchar(' '); - printf("<%s> a:0x%x(%d) b:0x%x(%d) c:0x%x(%d)\n", - p, a, a, b, b, c, c); - } - -//--------------------------------------------------------- -// MidiEventBase::write -//--------------------------------------------------------- - -void MidiEventBase::write(Xml& xml, const Pos& offset) const - { - QString s = QString("event tick=\"%1\"").arg(tick() + offset.tick()); - - switch (type()) { - case Note: - s += QString(" len=\"%1\"").arg(lenTick()); - break; - default: - s += QString(" type=\"%1\"").arg(type()); - break; - } - if (edata.dataLen) { - s += QString(" datalen=\"%1\"").arg(edata.dataLen); - xml.tag(s.toLatin1().data()); - QString data; - - int col = 0; - xml.putLevel(); - for (int i = 0; i < edata.dataLen; ++i, ++col) { - if (col >= 16) { - xml.put(""); - col = 0; - xml.putLevel(); - } - xml.nput("%02x ", edata.data[i] & 0xff); - } - if (col) - xml.put(""); - xml.etag("event"); - } - else { - if (a) - s += QString(" a=\"%1\"").arg(a); - if (b) - s += QString(" b=\"%1\"").arg(b); - if (c) - s += QString(" c=\"%1\"").arg(c); - xml.tagE(s.toLatin1().data()); - } - } - -//--------------------------------------------------------- -// MidiEventBase::read -//--------------------------------------------------------- - -void MidiEventBase::read(QDomNode node) - { - QDomElement e = node.toElement(); - setTick(e.attribute("tick","0").toInt()); - setType(EventType(e.attribute("type","0").toInt())); - setLenTick(e.attribute("len","0").toInt()); - a = e.attribute("a","0").toInt(); - b = e.attribute("b","0").toInt(); - c = e.attribute("c","0").toInt(); - int dataLen = e.attribute("datalen","0").toInt(); - - if (dataLen) { - QStringList l = e.text().simplified().split(" ", QString::SkipEmptyParts); - if (dataLen != l.size()) { - printf("error converting init string <%s>\n", e.text().toLatin1().data()); - } - edata.data = new unsigned char[dataLen]; - edata.dataLen = dataLen; - unsigned char* d = edata.data; - int numberBase = 16; - for (int i = 0; i < l.size(); ++i) { - bool ok; - *d++ = l.at(i).toInt(&ok, numberBase); - if (!ok) - printf("error converting init val <%s>\n", l.at(i).toLatin1().data()); - } - } - } - diff --git a/muse/muse/midievent.h b/muse/muse/midievent.h new file mode 100644 index 00000000..3712a607 --- /dev/null +++ b/muse/muse/midievent.h @@ -0,0 +1,118 @@ +//============================================================================= +// MusE +// Linux Music Editor +// $Id:$ +// +// Copyright (C) 2002-2006 by Werner Schweer and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= + +#ifndef __MPEVENT_H__ +#define __MPEVENT_H__ + +#include +#include "evdata.h" +#include + +#include "midi.h" + +class Event; +class EvData; + +//--------------------------------------------------------- +// MidiEvent +//--------------------------------------------------------- + +class MidiEvent { + unsigned _time; + EvData edata; + unsigned char _channel, _type; + int _a, _b; + + public: + MidiEvent() {} + MidiEvent(unsigned tm, int c, int t, int a, int b) + : _time(tm), _channel(c & 0xf), _type(t), _a(a), _b(b) {} + MidiEvent(unsigned t, int type, const unsigned char* data, int len); + MidiEvent(unsigned t, int tpe, EvData d) : _time(t), edata(d), _type(tpe) {} + MidiEvent(unsigned t, int channel, const Event& e); + + ~MidiEvent() {} + + MidiEvent& operator=(const MidiEvent& ed) { + _time = ed._time; + edata = ed.edata; + _channel = ed._channel; + _type = ed._type; + _a = ed._a; + _b = ed._b; + return *this; + } + + int channel() const { return _channel; } + int type() const { return _type; } + int dataA() const { return _a; } + int dataB() const { return _b; } + unsigned time() const { return _time; } + + void setChannel(int val) { _channel = val; } + void setType(int val) { _type = val; } + void setA(int val) { _a = val; } + void setB(int val) { _b = val; } + void setTime(unsigned val) { _time = val; } + + const EvData& eventData() const { return edata; } + unsigned char* data() const { return edata.data; } + int len() const { return edata.dataLen; } + void setData(const EvData& e) { edata = e; } + void setData(const unsigned char* p, int len) { edata.setData(p, len); } + void dump() const; + bool isNote() const { return _type == ME_NOTEON; } + bool isNoteOff() const { return (_type == ME_NOTEOFF)||(_type == ME_NOTEON && _b == 0); } + bool operator<(const MidiEvent&) const; + }; + +//--------------------------------------------------------- +// MPEventList +//--------------------------------------------------------- + +// typedef std::multiset, +// __gnu_cxx::__mt_alloc > MPEL; + +typedef std::multiset > MPEL; + +struct MPEventList : public MPEL { + void add(const MidiEvent& ev) { MPEL::insert(ev); } + }; + +typedef MPEventList::iterator iMPEvent; +typedef MPEventList::const_iterator ciMPEvent; + +//--------------------------------------------------------- +// MREventList +//--------------------------------------------------------- + +// typedef std::list > MREL; + +typedef std::list MREL; + +struct MREventList : public MREL { + void add(const MidiEvent& ev) { MREL::push_back(ev); } + }; + +typedef MREventList::iterator iMREvent; +typedef MREventList::const_iterator ciMREvent; + +#endif + diff --git a/muse/muse/midieventbase.cpp b/muse/muse/midieventbase.cpp new file mode 100644 index 00000000..0f4b77d3 --- /dev/null +++ b/muse/muse/midieventbase.cpp @@ -0,0 +1,163 @@ +//============================================================================= +// MusE +// Linux Music Editor +// $Id:$ +// +// Copyright (C) 2002-2006 by Werner Schweer and others +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +//============================================================================= + +#include "event.h" +#include "midieventbase.h" +#include "al/xml.h" +#include "midievent.h" +#include "midictrl.h" +#include "muse.h" + +//--------------------------------------------------------- +// MidiEventBase +//--------------------------------------------------------- + +MidiEventBase::MidiEventBase(EventType t) + : EventBase(t) + { + a = 0; + b = 0; + c = 0; + } + +//--------------------------------------------------------- +// MidiEventBase::mid +//--------------------------------------------------------- + +EventBase* MidiEventBase::mid(unsigned b, unsigned e) + { + if (tick() < b || tick() >= e) + return 0; + return new MidiEventBase(*this); + } + +//--------------------------------------------------------- +// isNoteOff +//--------------------------------------------------------- + +bool MidiEventBase::isNoteOff() const + { + return (type() == Note && (velo() == 0)); + } + +bool MidiEventBase::isNoteOff(const Event& e) const + { + return (e.isNoteOff() && (e.pitch() == a)); + } + +void MidiEventBase::dump(int n) const + { + EventBase::dump(n); + char* p; + + switch(type()) { + case Note: p = "Note "; break; + case Controller: p = "Ctrl "; break; + case Sysex: p = "Sysex "; break; + case PAfter: p = "PAfter "; break; + case CAfter: p = "CAfter "; break; + case Meta: p = "Meta "; break; + default: p = "?? "; break; + } + for (int i = 0; i < (n+2); ++i) + putchar(' '); + printf("<%s> a:0x%x(%d) b:0x%x(%d) c:0x%x(%d)\n", + p, a, a, b, b, c, c); + } + +//--------------------------------------------------------- +// MidiEventBase::write +//--------------------------------------------------------- + +void MidiEventBase::write(Xml& xml, const Pos& offset) const + { + QString s = QString("event tick=\"%1\"").arg(tick() + offset.tick()); + + switch (type()) { + case Note: + s += QString(" len=\"%1\"").arg(lenTick()); + break; + default: + s += QString(" type=\"%1\"").arg(type()); + break; + } + if (edata.dataLen) { + s += QString(" datalen=\"%1\"").arg(edata.dataLen); + xml.tag(s.toLatin1().data()); + QString data; + + int col = 0; + xml.putLevel(); + for (int i = 0; i < edata.dataLen; ++i, ++col) { + if (col >= 16) { + xml.put(""); + col = 0; + xml.putLevel(); + } + xml.nput("%02x ", edata.data[i] & 0xff); + } + if (col) + xml.put(""); + xml.etag("event"); + } + else { + if (a) + s += QString(" a=\"%1\"").arg(a); + if (b) + s += QString(" b=\"%1\"").arg(b); + if (c) + s += QString(" c=\"%1\"").arg(c); + xml.tagE(s.toLatin1().data()); + } + } + +//--------------------------------------------------------- +// MidiEventBase::read +//--------------------------------------------------------- + +void MidiEventBase::read(QDomNode node) + { + QDomElement e = node.toElement(); + setTick(e.attribute("tick","0").toInt()); + setType(EventType(e.attribute("type","0").toInt())); + setLenTick(e.attribute("len","0").toInt()); + a = e.attribute("a","0").toInt(); + b = e.attribute("b","0").toInt(); + c = e.attribute("c","0").toInt(); + int dataLen = e.attribute("datalen","0").toInt(); + + if (dataLen) { + QStringList l = e.text().simplified().split(" ", QString::SkipEmptyParts); + if (dataLen != l.size()) { + printf("error converting init string <%s>\n", e.text().toLatin1().data()); + } + edata.data = new unsigned char[dataLen]; + edata.dataLen = dataLen; + unsigned char* d = edata.data; + int numberBase = 16; + for (int i = 0; i < l.size(); ++i) { + bool ok; + *d++ = l.at(i).toInt(&ok, numberBase); + if (!ok) + printf("error converting init val <%s>\n", l.at(i).toLatin1().data()); + } + } + } + diff --git a/muse/muse/midifile.cpp b/muse/muse/midifile.cpp index e6eb051b..81c48a3f 100644 --- a/muse/muse/midifile.cpp +++ b/muse/muse/midifile.cpp @@ -26,7 +26,7 @@ #include "globals.h" #include "midictrl.h" #include "midictrl.h" -#include "mpevent.h" +#include "midievent.h" #include "gconfig.h" const char* errString[] = { diff --git a/muse/muse/mpevent.cpp b/muse/muse/mpevent.cpp index a3f549f4..573302c0 100644 --- a/muse/muse/mpevent.cpp +++ b/muse/muse/mpevent.cpp @@ -18,7 +18,7 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //============================================================================= -#include "mpevent.h" +#include "midievent.h" #include "helper.h" #include "event.h" diff --git a/muse/muse/mpevent.h b/muse/muse/mpevent.h deleted file mode 100644 index 3712a607..00000000 --- a/muse/muse/mpevent.h +++ /dev/null @@ -1,118 +0,0 @@ -//============================================================================= -// MusE -// Linux Music Editor -// $Id:$ -// -// Copyright (C) 2002-2006 by Werner Schweer and others -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License version 2. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -//============================================================================= - -#ifndef __MPEVENT_H__ -#define __MPEVENT_H__ - -#include -#include "evdata.h" -#include - -#include "midi.h" - -class Event; -class EvData; - -//--------------------------------------------------------- -// MidiEvent -//--------------------------------------------------------- - -class MidiEvent { - unsigned _time; - EvData edata; - unsigned char _channel, _type; - int _a, _b; - - public: - MidiEvent() {} - MidiEvent(unsigned tm, int c, int t, int a, int b) - : _time(tm), _channel(c & 0xf), _type(t), _a(a), _b(b) {} - MidiEvent(unsigned t, int type, const unsigned char* data, int len); - MidiEvent(unsigned t, int tpe, EvData d) : _time(t), edata(d), _type(tpe) {} - MidiEvent(unsigned t, int channel, const Event& e); - - ~MidiEvent() {} - - MidiEvent& operator=(const MidiEvent& ed) { - _time = ed._time; - edata = ed.edata; - _channel = ed._channel; - _type = ed._type; - _a = ed._a; - _b = ed._b; - return *this; - } - - int channel() const { return _channel; } - int type() const { return _type; } - int dataA() const { return _a; } - int dataB() const { return _b; } - unsigned time() const { return _time; } - - void setChannel(int val) { _channel = val; } - void setType(int val) { _type = val; } - void setA(int val) { _a = val; } - void setB(int val) { _b = val; } - void setTime(unsigned val) { _time = val; } - - const EvData& eventData() const { return edata; } - unsigned char* data() const { return edata.data; } - int len() const { return edata.dataLen; } - void setData(const EvData& e) { edata = e; } - void setData(const unsigned char* p, int len) { edata.setData(p, len); } - void dump() const; - bool isNote() const { return _type == ME_NOTEON; } - bool isNoteOff() const { return (_type == ME_NOTEOFF)||(_type == ME_NOTEON && _b == 0); } - bool operator<(const MidiEvent&) const; - }; - -//--------------------------------------------------------- -// MPEventList -//--------------------------------------------------------- - -// typedef std::multiset, -// __gnu_cxx::__mt_alloc > MPEL; - -typedef std::multiset > MPEL; - -struct MPEventList : public MPEL { - void add(const MidiEvent& ev) { MPEL::insert(ev); } - }; - -typedef MPEventList::iterator iMPEvent; -typedef MPEventList::const_iterator ciMPEvent; - -//--------------------------------------------------------- -// MREventList -//--------------------------------------------------------- - -// typedef std::list > MREL; - -typedef std::list MREL; - -struct MREventList : public MREL { - void add(const MidiEvent& ev) { MREL::push_back(ev); } - }; - -typedef MREventList::iterator iMREvent; -typedef MREventList::const_iterator ciMREvent; - -#endif - diff --git a/muse/muse/synth.cpp b/muse/muse/synth.cpp index 5d1a959c..421e0a96 100644 --- a/muse/muse/synth.cpp +++ b/muse/muse/synth.cpp @@ -29,7 +29,7 @@ #include "song.h" #include "audio.h" #include "event.h" -#include "mpevent.h" +#include "midievent.h" #include "audio.h" #include "midiseq.h" #include "midictrl.h" -- cgit v1.2.3