23 #ifndef EVORAL_EVENT_HPP
24 #define EVORAL_EVENT_HPP
41 #define EVORAL_EVENT_ALLOC 1
53 template<
typename Time>
56 #ifdef EVORAL_EVENT_ALLOC
73 void set(
const uint8_t* buf, uint32_t size, Time t);
76 if (_type != other.
_type || _time != other.
_time || _size != other.
_size) {
79 return !memcmp(_buf, other.
_buf, _size);
91 inline void set_buffer(uint32_t size, uint8_t* buf,
bool own) {
104 _buf = (uint8_t*) ::realloc(_buf, size);
106 _buf = (uint8_t*) ::malloc(size);
123 inline Time
time()
const {
return _time; }
124 inline uint32_t
size()
const {
return _size; }
125 inline const uint8_t*
buffer()
const {
return _buf; }
126 inline uint8_t*
buffer() {
return _buf; }
145 uint8_t
type()
const {
return _buf[0] & 0xF0; }
146 uint8_t
channel()
const {
return _buf[0] & 0x0F; }
149 bool is_note()
const {
return is_note_on() || is_note_off(); }
157 bool is_sysex()
const {
return _buf[0] == 0xF0 || _buf[0] == 0xF7; }
159 bool is_spp()
const {
return _buf[0] == 0xF2 && size() == 1; }
160 bool is_song()
const {
return _buf[0] == 0xF3 && size() == 1; }
161 bool is_tune()
const {
return _buf[0] == 0xF6 && size() == 1; }
162 bool is_eox()
const {
return _buf[0] == 0xF7 && size() == 1; }
163 bool is_clock()
const {
return _buf[0] == 0xF8 && size() == 1; }
164 bool is_tick()
const {
return _buf[0] == 0xF9 && size() == 1; }
166 _buf[0] == 0xF0 && _buf[1] == 0x7F &&
167 _buf[3] == 0x01 && _buf[4] == 0x01); }
168 bool is_realtime()
const {
return is_mtc_full() || ((_buf[0] >= 0xF1 && _buf[0] <= 0xfe) && size() == 1); }
169 uint8_t
note()
const {
return _buf[1]; }
179 uint16_t
pitch_bender_value()
const {
return (uint16_t) ((0x7F & _buf[2]) << 7 | (0x7F & _buf[1])); }
181 void set_channel(uint8_t channel) { _buf[0] = (0xF0 & _buf[0]) | (0x0F & channel); }
182 void set_type(uint8_t type) { _buf[0] = (0x0F & _buf[0]) | (0xF0 & type); }
190 factor = std::max (factor, 0.0f);
191 set_velocity ((uint8_t) (std::min (127L, lrintf (velocity() * factor))));
199 return pitch_bender_value();
201 return poly_pressure();
203 return channel_pressure();
217 #ifdef EVORAL_EVENT_ALLOC
222 template<
typename Time>
224 o <<
"Event #" << ev.
id() <<
" type = " << ev.
event_type() <<
" @ " << ev.
time();
226 for (uint32_t n = 0; n < ev.
size(); ++n) {
227 o <<
' ' << (int) ev.
buffer()[n];
void assign(const Event &other)
void set(const uint8_t *buf, uint32_t size, Time t)
EventType event_type() const
bool is_poly_pressure() const
EventType _type
Type of event (application relative, NOT MIDI 'type')
bool operator!=(const Event &other) const
Event(const Event ©, bool alloc)
bool is_channel_event() const
void set_velocity(uint8_t val)
uint32_t _size
Size of buffer in bytes.
uint8_t poly_pressure() const
bool is_live_midi() const
uint8_t cc_number() const
Time _time
Time stamp of event.
uint8_t * _buf
Event contents (e.g. raw MIDI data)
uint8_t pitch_bender_lsb() const
const uint8_t * buffer() const
void scale_velocity(float factor)
void set_event_type(EventType t)
bool is_mtc_quarter() const
void realloc(uint32_t size)
uint8_t channel_pressure() const
bool is_channel_pressure() const
bool is_smf_meta_event() const
void set_id(event_id_t n)
event_id_t _id
Unique event ID.
Event(EventType type=NO_EVENT, Time time=Time(), uint32_t size=0, uint8_t *buf=NULL, bool alloc=false)
bool is_pgm_change() const
uint8_t pgm_number() const
void set_pgm_number(uint8_t num)
Event(EventType type, Time time, uint32_t size, const uint8_t *buf)
void set_channel(uint8_t channel)
bool is_pitch_bender() const
void set_cc_value(uint8_t val)
void set_note(uint8_t num)
uint8_t pitch_bender_msb() const
void set_type(uint8_t type)
uint8_t poly_note() const
uint16_t pitch_bender_value() const
bool operator==(const Event &other) const
void set_cc_number(uint8_t num)
void set_buffer(uint32_t size, uint8_t *buf, bool own)
bool _owns_buf
Whether buffer is locally allocated.
#define MIDI_CMD_NOTE_PRESSURE
#define MIDI_CMD_PGM_CHANGE
#define MIDI_CMD_CHANNEL_PRESSURE
#define MIDI_CMD_NOTE_OFF
event_id_t next_event_id()
event_id_t event_id_counter()
std::ostream & operator<<(std::ostream &o, const Evoral::Event< Time > &ev)
void init_event_id_counter(event_id_t n)
bool operator==(const ProcessorSelection &a, const ProcessorSelection &b)