NAP
midievent.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 #include <nap/event.h>
8 
9 namespace nap
10 {
11 
15  using MidiValue = short;
16 
17 
22  class NAPAPI MidiEvent : public nap::Event
23  {
24  public:
25  inline static constexpr MidiValue MIDI_MAX_VALUE = 127;
26  inline static constexpr MidiValue MIDI_CONTROLLER_SUSTAIN = 64;
27  inline static constexpr MidiValue MIDI_VALUE_OMNI = -1;
28  inline static constexpr MidiValue MIDI_NUMBER_OMNI = MIDI_VALUE_OMNI;
29  inline static constexpr MidiValue MIDI_CHANNEL_OMNI = MIDI_VALUE_OMNI;
30  inline static constexpr MidiValue MIDI_NUMBER_NONE = 0;
31 
35  enum class Type
36  {
37  noteOff = 0x80,
38  noteOn = 0x90,
39  afterTouch = 0xA0,
40  controlChange = 0xB0,
41  programChange = 0xC0,
42  channelPressure = 0xD0,
43  pitchBend = 0xE0
44  };
45 
46  MidiEvent() = default;
47 
51  MidiEvent(Type aType, MidiValue number = MIDI_NUMBER_OMNI, MidiValue value = MIDI_VALUE_OMNI, MidiValue channel = MIDI_CHANNEL_OMNI, const std::string& port = "");
52 
56  MidiEvent(const std::vector<unsigned char>& data, const std::string& port);
57 
58  virtual ~MidiEvent() = default;
59 
63  bool corresponds(const MidiEvent &b) const;
64 
65  bool operator ==(const MidiEvent &rhs) const;
66  bool operator >(const MidiEvent &rhs) const { return mNumber > rhs.mNumber; }
67  bool operator <(const MidiEvent &rhs) const { return mNumber < rhs.mNumber; }
68 
69  Type getType() const { return mType; }
70  MidiValue getNumber() const { return mNumber; }
71  MidiValue getValue() const { return mValue; }
72  MidiValue getNoteNumber() const { return mNumber; }
73  MidiValue getVelocity() const { return mValue; }
74  MidiValue getCCNumber() const { return mNumber; }
75  MidiValue getCCValue() const { return mValue; }
76  float getPitchBendValue() const;
77  MidiValue getProgramNumber() const { return mNumber; }
78  MidiValue getChannel() const { return mChannel; }
79  std::string getPort() const { return mPort; }
84  std::string toString() const;
85 
89  std::vector<unsigned char> getData() const;
90 
91  private:
92  Type mType;
93  MidiValue mNumber;
94  MidiValue mValue = MIDI_VALUE_OMNI;
95  MidiValue mChannel = MIDI_CHANNEL_OMNI;
96  std::string mPort = "";
97  };
98 
99 }
nap::toString
NAPAPI std::string toString(EDay day)
nap::MidiEvent::Type
Type
Definition: midievent.h:35
nap::Event
Definition: event.h:17
nap::MidiEvent
Definition: midievent.h:22
nap
Definition: templateapp.h:17
nap::MidiValue
short MidiValue
Definition: midievent.h:15