Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/midi/midimessage.cpp

Go to the documentation of this file.
00001 #include <QtCore>
00002 #include <QtXml>
00003 #include "midimessage.h"
00004 
00006 MidiMessage::MidiMessage(MidiStatusByte status, int midino, char midichannel)
00007 {
00008     //Register this class with QT so we can use this bad boy in signals/slots.
00009     qRegisterMetaType<MidiMessage>("MidiMessage");
00010     qRegisterMetaType<MidiStatusByte>("MidiStatusByte");
00011 
00012     m_midiStatusByte = status;
00013     m_midiNo = midino;
00014     m_midiStatusByte |= midichannel; //Jam midichannel into low nibble of status byte.
00015 
00016     m_midiByte2On = 0x7F; 
00017     m_midiByte2Off = 0x00;
00018 }
00019 
00023 MidiMessage::MidiMessage(QDomElement& parentNode)
00024 {
00025     // For each control
00026 
00027     QString midiStatus = parentNode.firstChildElement("status").text();
00028     QString midiNo = parentNode.firstChildElement("midino").text();
00029     QString midiOn = parentNode.firstChildElement("on").text();
00030     QString midiOff = parentNode.firstChildElement("off").text();
00031 
00032     bool ok = false;
00033 
00034     //Use QString with toInt base of 0 to auto convert hex values
00035     m_midiNo = midiNo.toInt(&ok, 0);
00036     if (!ok)
00037         m_midiNo = 0x00;
00038 
00039     m_midiStatusByte = midiStatus.toInt(&ok, 0);
00040     if (!ok)
00041         m_midiStatusByte = 0x00;
00042 
00043     m_midiByte2On = midiOn.toInt(&ok, 0);
00044     if (!ok)
00045         m_midiByte2On = 0x7F;
00046 
00047     m_midiByte2Off = midiOff.toInt(&ok, 0);
00048     if (!ok)
00049         m_midiByte2Off = 0x00;
00050 }
00051 
00052 void MidiMessage::serializeToXML(QDomElement& parentNode, bool isOutputNode) const
00053 {
00054     QDomText text;
00055     QDomDocument nodeMaker;
00056     QDomElement tagNode;
00057 
00058     //Midi status byte
00059     tagNode = nodeMaker.createElement("status");
00060     QString strMidiStatus;
00061     text = nodeMaker.createTextNode(QString("0x%1").arg(this->getMidiStatusByte(), 0, 16));
00062     tagNode.appendChild(text);
00063     parentNode.appendChild(tagNode);
00064 
00065     //Midi no
00066     tagNode = nodeMaker.createElement("midino");
00067     text = nodeMaker.createTextNode(QString("0x%1").arg(this->getMidiNo(), 0, 16)); //Base 16
00068     tagNode.appendChild(text);
00069     parentNode.appendChild(tagNode);
00070 
00071     //If we're writing to an <output> node, include the <on> and <off> MIDI "Byte 2" info
00072     if (isOutputNode)
00073     {
00074         //Midi Byte 2 for to turn on LEDs
00075         tagNode = nodeMaker.createElement("on");
00076         text = nodeMaker.createTextNode(QString("0x%1").arg(this->getMidiByte2On(), 0, 16)); //Base 16
00077         tagNode.appendChild(text);
00078         parentNode.appendChild(tagNode);
00079 
00080         //Midi Byte 2 for to turn off LEDs
00081         tagNode = nodeMaker.createElement("off");
00082         text = nodeMaker.createTextNode(QString("0x%1").arg(this->getMidiByte2Off(), 0, 16)); //Base 16
00083         tagNode.appendChild(text);
00084         parentNode.appendChild(tagNode);
00085     }
00086 }
00087 
00088 QString MidiMessage::toString() const
00089 {
00090     QString channel = "Channel: " + QString("%1").arg(this->getMidiChannel()) + "\n";
00091     QString status = "Status: " + QString("%1").arg(this->getMidiStatusByte()) + "\n";
00092     QString midino = "Number: " + QString("%1").arg(this->getMidiNo()) + "\n";
00093 
00094     QString hooah = channel + status + midino;
00095     return hooah;
00096 }
00097 
00098 uint qHash(const MidiMessage& key)
00099 {
00100     //& with 0xF0 to ignore the channel bits for comparison purposes.
00101     unsigned short status = key.getMidiStatusByte();
00102     if ((status & 0xF0) == MIDI_STATUS_PITCH_BEND ||
00103         (status & 0xF0) == MIDI_STATUS_CH_AFTERTOUCH ||
00104         (status & 0xF0) == MIDI_STATUS_SYSEX) { 
00105         //Ignore midino for pitch bend, channel after-touch and 0xFn messages
00106         //  because that byte is part of the message payload.
00107         return status; 
00108     }
00109     else
00110         return (key.getMidiByte2On() << 16) | (key.getMidiStatusByte() << 8) | key.getMidiNo();
00111 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines