2 Copyright (C) 2015 Paul Davis
3 Author: David Robillard
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __ardour_note_fixer_h__
21 #define __ardour_note_fixer_h__
25 #include <boost/utility.hpp>
27 #include "ardour/midi_model.h"
28 #include "ardour/types.h"
29 #include "evoral/Beats.hpp"
30 #include "evoral/Note.hpp"
32 namespace Evoral { template<typename Time> class EventSink; }
36 class BeatsFramesConverter;
37 class MidiStateTracker;
40 /** A tracker and compensator for note edit operations.
42 * This monitors edit operations sent to a model that affect active notes
43 * during a read, and maintains a queue of synthetic events that should be sent
44 * at the start of the next read to maintain coherent MIDI state.
46 class NoteFixer : public boost::noncopyable
49 typedef Evoral::Note<Evoral::Beats> Note;
53 /** Clear all internal state. */
56 /** Handle a region edit during read.
58 * This must be called before the command is applied to the model. Events
59 * are enqueued to compensate for edits which should be later sent with
60 * emit() at the start of the next read.
62 * @param cmd Command to compensate for.
63 * @param origin Timeline position of edited source.
64 * @param pos Current read position (last read end).
66 void prepare(TempoMap& tempo_map,
67 const MidiModel::NoteDiffCommand* cmd,
70 std::set< boost::weak_ptr<Note> >& active_notes);
72 /** Emit any pending edit compensation events.
74 * @param dst Destination for events.
75 * @param pos Timestamp to be used for every event, should be the start of
76 * the read block immediately following any calls to prepare().
77 * @param tracker Tracker to update with emitted events.
79 void emit(Evoral::EventSink<framepos_t>& dst,
81 MidiStateTracker& tracker);
84 typedef Evoral::Event<framepos_t> Event;
85 typedef std::list<Event*> Events;
87 /** Copy a beats event to a frames event with the given time stamp. */
88 Event* copy_event(framepos_t time, const Evoral::Event<Evoral::Beats>& ev);
90 /** Return true iff `note` is active at `pos`. */
91 bool note_is_active(const BeatsFramesConverter& converter,
92 boost::shared_ptr<Note> note,
98 } /* namespace ARDOUR */
100 #endif /* __ardour_note_fixer_h__ */