ardour
note_player.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 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 
19 #include <sigc++/bind.h>
20 #include <glibmm/main.h>
21 
22 #include "ardour/midi_track.h"
23 
24 #include "note_player.h"
25 
26 using namespace ARDOUR;
27 using namespace std;
28 
30  : track (mt)
31 {
32 }
33 
35 {
36  clear ();
37 }
38 
39 void
41 {
42  notes.push_back (note);
43 }
44 
45 void
47 {
48  off ();
49  notes.clear ();
50 }
51 
52 void
54 {
55  for (Notes::iterator n = notes.begin(); n != notes.end(); ++n) {
56  track->write_immediate_event ((*n)->on_event().size(), (*n)->on_event().buffer());
57  }
58 }
59 
60 void
62 {
63  on ();
64 
65  /* note: if there is more than 1 note, we will silence them all at the same time
66  */
67 
68  const uint32_t note_length_ms = 100;
69 
70  Glib::signal_timeout().connect (sigc::bind (sigc::ptr_fun (&NotePlayer::_off), this),
71  note_length_ms, G_PRIORITY_DEFAULT);
72 }
73 
74 bool
76 {
77  np->off ();
78  delete np;
79  return false;
80 }
81 
82 void
84 {
85  for (Notes::iterator n = notes.begin(); n != notes.end(); ++n) {
86  track->write_immediate_event ((*n)->off_event().size(), (*n)->off_event().buffer());
87  }
88 }
void off()
Definition: note_player.cc:83
Definition: Beats.hpp:239
void add(boost::shared_ptr< NoteType >)
Definition: note_player.cc:40
Definition: amp.h:29
bool write_immediate_event(size_t size, const uint8_t *buf)
Definition: midi_track.cc:667
void clear()
Definition: note_player.cc:46
static bool _off(NotePlayer *)
Definition: note_player.cc:75
NotePlayer(boost::shared_ptr< ARDOUR::MidiTrack >)
Definition: note_player.cc:29
Notes notes
Definition: note_player.h:51
void on()
Definition: note_player.cc:53
boost::shared_ptr< ARDOUR::MidiTrack > track
Definition: note_player.h:50
void play()
Definition: note_player.cc:61