Optimize automation-event process splitting
[ardour.git] / libs / ardour / ardour / midi_port.h
1 /*
2     Copyright (C) 2002 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id: port.h 712 2006-07-28 01:08:57Z drobilla $
19 */
20
21 #ifndef __ardour_midi_port_h__
22 #define __ardour_midi_port_h__
23
24 #include "midi++/parser.h"
25
26 #include "ardour/port.h"
27 #include "ardour/midi_buffer.h"
28
29 namespace ARDOUR {
30
31 class MidiBuffer;
32 class MidiEngine;
33
34 class LIBARDOUR_API MidiPort : public Port {
35    public:
36         ~MidiPort();
37
38         DataType type () const {
39                 return DataType::MIDI;
40         }
41
42         void cycle_start (pframes_t nframes);
43         void cycle_end (pframes_t nframes);
44         void cycle_split ();
45
46         void flush_buffers (pframes_t nframes);
47         void transport_stopped ();
48         void realtime_locate ();
49         void reset ();
50         void require_resolve ();
51
52         bool input_active() const { return _input_active; }
53         void set_input_active (bool yn);
54
55         Buffer& get_buffer (pframes_t nframes) {
56                 return get_midi_buffer (nframes);
57         }
58
59         MidiBuffer& get_midi_buffer (pframes_t nframes);
60
61         void set_trace (MIDI::Parser* trace_parser);
62
63         typedef boost::function<bool(MidiBuffer&,MidiBuffer&)> MidiFilter;
64         void set_inbound_filter (MidiFilter);
65         int add_shadow_port (std::string const &, MidiFilter);
66         boost::shared_ptr<MidiPort> shadow_port() const { return _shadow_port; }
67
68         void read_and_parse_entire_midi_buffer_with_no_speed_adjustment (pframes_t nframes, MIDI::Parser& parser, samplepos_t now);
69
70   protected:
71         friend class PortManager;
72
73         MidiPort (const std::string& name, PortFlags);
74
75   private:
76         MidiBuffer* _buffer;
77         bool        _resolve_required;
78         bool        _input_active;
79         MidiFilter   inbound_midi_filter;
80         boost::shared_ptr<MidiPort> _shadow_port;
81         MidiFilter   shadow_midi_filter;
82         MIDI::Parser* _trace_parser;
83         bool  _data_fetched_for_cycle;
84         
85         void resolve_notes (void* buffer, samplepos_t when);
86         void pull_input (pframes_t nframes, bool adjust_speed);
87         void parse_input (pframes_t nframes, MIDI::Parser& parser);
88 };
89
90 } // namespace ARDOUR
91
92 #endif /* __ardour_midi_port_h__ */