Delete trailing whitespace
[ardour.git] / gtk2_ardour / note_player.cc
1 #include <sigc++/bind.h>
2 #include <glibmm/main.h>
3
4 #include "ardour/midi_track.h"
5 #include "ardour/session.h"
6
7 #include "note_player.h"
8
9 using namespace ARDOUR;
10 using namespace std;
11
12 NotePlayer::NotePlayer (boost::shared_ptr<MidiTrack> mt)
13         : track (mt)
14 {
15 }
16
17 void
18 NotePlayer::add (boost::shared_ptr<NoteType> note)
19 {
20         notes.push_back (note);
21 }
22
23 void
24 NotePlayer::play ()
25 {
26         Evoral::MusicalTime longest_duration_beats = 0;
27
28         /* note: if there is more than 1 note, we will silence them all at the same time
29          */
30
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();
35                 }
36         }
37
38         uint32_t note_length_ms = 350;
39         /* beats_to_frames (longest_duration_beats)
40          * (1000 / (double)track->session().nominal_frame_rate()); */
41
42         Glib::signal_timeout().connect(sigc::bind (sigc::ptr_fun (&NotePlayer::_off), this),
43                                        note_length_ms, G_PRIORITY_DEFAULT);
44 }
45
46 bool
47 NotePlayer::_off (NotePlayer* np)
48 {
49         np->off ();
50         delete np;
51         return false;
52 }
53
54 void
55 NotePlayer::off ()
56 {
57         for (NoteList::iterator n = notes.begin(); n != notes.end(); ++n) {
58                 track->write_immediate_event((*n)->off_event().size(), (*n)->off_event().buffer());
59         }
60 }