1 /* ----------------------------------------------------------------------------- 2 * 3 * Giada - Your Hardcore Loopmachine 4 * 5 * ----------------------------------------------------------------------------- 6 * 7 * Copyright (C) 2010-2020 Giovanni A. Zuliani | Monocasual 8 * 9 * This file is part of Giada - Your Hardcore Loopmachine. 10 * 11 * Giada - Your Hardcore Loopmachine is free software: you can 12 * redistribute it and/or modify it under the terms of the GNU General 13 * Public License as published by the Free Software Foundation, either 14 * version 3 of the License, or (at your option) any later version. 15 * 16 * Giada - Your Hardcore Loopmachine is distributed in the hope that it 17 * will be useful, but WITHOUT ANY WARRANTY; without even the implied 18 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 * See the GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with Giada - Your Hardcore Loopmachine. If not, see 23 * <http://www.gnu.org/licenses/>. 24 * 25 * -------------------------------------------------------------------------- */ 26 27 28 #ifndef G_MIDI_EVENT_H 29 #define G_MIDI_EVENT_H 30 31 32 #include <cstdint> 33 34 35 namespace giada { 36 namespace m 37 { 38 class MidiEvent 39 { 40 public: 41 42 static const int NOTE_ON = 0x90; 43 static const int NOTE_OFF = 0x80; 44 static const int NOTE_KILL = 0x70; 45 static const int ENVELOPE = 0xB0; 46 47 /* MidiEvent (1) 48 Creates and empty and invalid MIDI event. */ 49 50 MidiEvent() = default; 51 52 MidiEvent(uint32_t raw); 53 MidiEvent(int byte1, int byte2, int byte3); 54 55 /* MidiEvent (4) 56 A constructor that takes a float parameter. Useful to build ENVELOPE events 57 for automations, volume and pitch. */ 58 59 MidiEvent(float v); 60 61 int getStatus() const; 62 int getChannel() const; 63 int getNote() const; 64 int getVelocity() const; 65 float getVelocityFloat() const; 66 bool isNoteOnOff() const; 67 int getDelta() const; 68 69 /* getRaw(), getRawNoVelocity() 70 Returns the raw MIDI message. If getRawNoVelocity(), the velocity value is 71 stripped off (i.e. velocity == 0). */ 72 73 uint32_t getRaw() const; 74 uint32_t getRawNoVelocity() const; 75 76 void setDelta(int d); 77 void setChannel(int c); 78 void setVelocity(int v); 79 80 /* fixVelocityZero() 81 According to the MIDI standard, there is a special case if the velocity is 82 set to zero. The NOTE ON message then has the same meaning as a NOTE OFF 83 message, switching the note off. Let's fix it. Sometime however you do want 84 a NOTE ON with velocity zero: setting velocity to 0 in MIDI action editor to 85 mute a specific event. */ 86 87 void fixVelocityZero(); 88 89 private: 90 91 int m_status; 92 int m_channel; 93 int m_note; 94 int m_velocity; 95 int m_delta; 96 }; 97 }} // giada::m:: 98 99 100 #endif 101