Ardour  8.12
midi_state_tracker.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2015 David Robillard <d@drobilla.net>
3  * Copyright (C) 2009-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2010-2011 Carl Hetherington <carl@carlh.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef __ardour_midi_state_tracker_h__
22 #define __ardour_midi_state_tracker_h__
23 
24 #include <glibmm/threads.h>
25 
26 #include "temporal/beats.h"
27 #include "ardour/midi_buffer.h"
28 #include "ardour/source.h"
29 
30 namespace Evoral {
31 template <typename T> class EventSink;
32 template <typename T> class EventList;
33 }
34 
35 namespace ARDOUR {
36 
37 class MidiSource;
38 
43 {
44 public:
46  virtual ~MidiNoteTracker() {}
47 
48  virtual void track (const uint8_t* evbuf);
49  virtual void dump (std::ostream&);
50  virtual void reset ();
51 
53  void add (uint8_t note, uint8_t chn);
54  void remove (uint8_t note, uint8_t chn);
55  void resolve_notes (MidiBuffer& buffer, samplepos_t time, bool reset = true);
58 
59  void flush_notes (MidiBuffer& buffer, samplepos_t time, bool reset = true);
60 
61  bool empty() const { return _on == 0; }
62  uint16_t on() const { return _on; }
63  bool active (uint8_t note, uint8_t channel) {
64  return _active_notes[(channel*128)+note] > 0;
65  }
66 
67  template<typename Time>
68  void track (const Evoral::Event<Time>& ev) {
69  track (ev.buffer());
70  }
71 
72 private:
73  uint8_t _active_notes[128*16];
74  uint16_t _on;
75 
76  void push_notes (MidiBuffer &dst, samplepos_t time, bool reset, int cmd, int velocity);
77 
78 };
79 
81 {
82  public:
85 
86  void track (const uint8_t* evbuf);
87  void dump (std::ostream&);
88  void reset ();
89 
92 
93  private:
94  uint8_t program[16];
95  uint16_t bender[16];
96  uint16_t pressure[16];
97  uint8_t control[16][127];
98 };
99 
100 } // namespace ARDOUR
101 
102 #endif // __ardour_midi_state_tracker_h__
void track(const Evoral::Event< Time > &ev)
void resolve_notes(MidiSource &src, const Source::WriterLock &lock, Temporal::Beats time)
void track(const MidiBuffer::const_iterator &from, const MidiBuffer::const_iterator &to)
virtual void dump(std::ostream &)
virtual void reset()
void push_notes(MidiBuffer &dst, samplepos_t time, bool reset, int cmd, int velocity)
void resolve_notes(MidiBuffer &buffer, samplepos_t time, bool reset=true)
void flush_notes(MidiBuffer &buffer, samplepos_t time, bool reset=true)
void resolve_notes(Evoral::EventSink< samplepos_t > &buffer, samplepos_t time)
void remove(uint8_t note, uint8_t chn)
bool active(uint8_t note, uint8_t channel)
virtual void track(const uint8_t *evbuf)
void add(uint8_t note, uint8_t chn)
void resolve_state(Evoral::EventSink< samplepos_t > &, Evoral::EventList< samplepos_t > const &, samplepos_t time, bool reset=true)
void track(const uint8_t *evbuf)
void dump(std::ostream &)
void flush(MidiBuffer &, samplepos_t, bool reset)
Glib::Threads::RWLock::WriterLock WriterLock
const uint8_t * buffer() const
Definition: Event.h:125
#define LIBARDOUR_API
Temporal::samplepos_t samplepos_t
Definition: editor.h:87