]> git.donarmstrong.com Git - lilypond.git/blob - lily/note-performer.cc
patch::: 0.0.75.jcn4: midi op
[lilypond.git] / lily / note-performer.cc
1 /*
2   note-performer.cc -- implement Note_performer
3
4   (c) 1996, 1997 Jan Nieuwenhuizen <jan@digicash.com>
5  */
6
7 #include "note-performer.hh"
8 #include "translator.hh"
9 #include "input-translator.hh"
10 #include "musical-request.hh"
11 #include "midi-item.hh"
12 #include "debug.hh"
13
14 IMPLEMENT_IS_TYPE_B1(Note_performer,Performer);
15 IMPLEMENT_STATIC_NAME(Note_performer);
16 ADD_THIS_PERFORMER(Note_performer);
17
18 Note_performer::Note_performer()
19 {
20     note_req_l_ = 0;
21     off_mom_ = 0;
22 }
23
24 Note_performer::~Note_performer()
25 {
26 }
27
28 void 
29 Note_performer::do_print() const
30 {
31 #ifndef NPRINT
32     if ( note_req_l_ )
33         note_req_l_->print();
34 #endif
35 }
36
37 void 
38 Note_performer::process_requests() 
39 {
40 //    if ( when() == off_mom_ )
41 //      play_event( Note_event( current_l_->pitch() ) );
42
43 //Midi_note( Melodic_req* melreq_l, int channel_i, bool on_bo  )
44
45     // this is _really_ braindead, but it generates some output
46     if ( !note_req_l_ || !note_req_l_->melodic()  || !note_req_l_->rhythmic() )
47         return;
48
49     // ugh, need to know channel (===track===staff) too
50     int channel_i = 0;
51     Moment mom = get_mom();
52     if ( !off_mom_ ) { // start note
53         off_mom_ = mom + note_req_l_->duration();
54         Midi_note n( note_req_l_->melodic(), channel_i, true );
55         play_event( &n );
56     }
57     else if ( mom == off_mom_ ) {
58         Midi_note n( note_req_l_->melodic(), channel_i, false );
59         play_event( &n );
60         note_req_l_ = 0;
61         off_mom_ = 0;
62     }
63 }
64
65 bool 
66 Note_performer::try_request( Request* req_l )
67 {
68     if ( note_req_l_ )
69         return false;
70     
71  // huh?
72 //    if (req_l->musical() && (req_l->musical()->note() || req_l->musical()->rest()))
73 //      note_req_l_ = req_l->musical()->rhythmic();
74     if ( req_l->musical() && req_l->musical()->note() )
75 // huh?
76         note_req_l_ = req_l->musical()->melodic();
77     else
78         return false;
79
80     return true;
81 }
82