Ardour  9.0-pre0-350-gf17a656217
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 #pragma once
22 
23 #include <glibmm/threads.h>
24 
25 #include "temporal/beats.h"
26 #include "ardour/midi_buffer.h"
27 #include "ardour/source.h"
28 
29 namespace Evoral {
30 template <typename T> class EventSink;
31 template <typename T> class EventList;
32 }
33 
34 namespace ARDOUR {
35 
36 class MidiSource;
37 
42 {
43 public:
45  virtual ~MidiNoteTracker() {}
46 
47  virtual void track (const uint8_t* evbuf);
48  virtual void dump (std::ostream&) const;
49  virtual void reset ();
50 
52  void add (uint8_t note, uint8_t chn);
53  void remove (uint8_t note, uint8_t chn);
54  void resolve_notes (MidiBuffer& buffer, samplepos_t time, bool reset = true);
57 
58  void flush_notes (MidiBuffer& buffer, samplepos_t time, bool reset = true);
59 
60  bool empty() const { return _on == 0; }
61  uint16_t on() const { return _on; }
62  bool active (uint8_t note, uint8_t channel) const {
63  return _active_notes[(channel*128)+note] > 0;
64  }
65 
66  template<typename Time>
67  void track (const Evoral::Event<Time>& ev) {
68  track (ev.buffer());
69  }
70 
71 private:
72  uint8_t _active_notes[128*16];
73  uint16_t _on;
74 
75  void push_notes (MidiBuffer &dst, samplepos_t time, bool reset, int cmd, int velocity);
76 
77 };
78 
80 {
81  public:
84 
85  void track (const uint8_t* evbuf);
86  void dump (std::ostream&) const;
87  void reset ();
88 
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 
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 &) const
bool active(uint8_t note, uint8_t channel) const
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)
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 resolve_diff(MidiStateTracker const &other, Evoral::EventSink< samplepos_t > &, samplepos_t time, bool reset=true)
void dump(std::ostream &) const
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:85