Zoom session when the mouse pointer is moved up and down during a playhead drag.
[ardour2.git] / gtk2_ardour / note_player.cc
blob3c577633b183aeefb063aad60b7231eec1adf1ff
1 #include <sigc++/bind.h>
2 #include <glibmm/main.h>
4 #include "ardour/midi_track.h"
5 #include "ardour/session.h"
7 #include "note_player.h"
9 using namespace ARDOUR;
10 using namespace std;
12 NotePlayer::NotePlayer (boost::shared_ptr<MidiTrack> mt)
13 : track (mt)
17 void
18 NotePlayer::add (boost::shared_ptr<NoteType> note)
20 notes.push_back (note);
23 void
24 NotePlayer::play ()
26 Evoral::MusicalTime longest_duration_beats = 0;
28 /* note: if there is more than 1 note, we will silence them all at the same time
31 for (NoteList::iterator n = notes.begin(); n != notes.end(); ++n) {
32 track->write_immediate_event ((*n)->on_event().size(), (*n)->on_event().buffer());
33 if ((*n)->length() > longest_duration_beats) {
34 longest_duration_beats = (*n)->length();
38 uint32_t note_length_ms = 350;
39 /* beats_to_frames (longest_duration_beats)
40 * (1000 / (double)track->session().nominal_frame_rate()); */
42 Glib::signal_timeout().connect(sigc::bind (sigc::ptr_fun (&NotePlayer::_off), this),
43 note_length_ms, G_PRIORITY_DEFAULT);
46 bool
47 NotePlayer::_off (NotePlayer* np)
49 np->off ();
50 delete np;
51 return false;
54 void
55 NotePlayer::off ()
57 for (NoteList::iterator n = notes.begin(); n != notes.end(); ++n) {
58 track->write_immediate_event((*n)->off_event().size(), (*n)->off_event().buffer());