(c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
*/
+#include <cassert>
#include "audio-element.hh"
for (; i.ok (); i++)
i.process ();
- midi_stream << midi_track;
+ midi_stream.write (midi_track);
}
int channel_;
DECLARE_CLASSNAME(Midi_channel_item);
Midi_channel_item ();
- virtual const char *name () const { return "Midi_channel_item"; }
- virtual ~Midi_channel_item ();
};
/**
int clocks_per_1_;
};
-/**
- Turn a note on.
-*/
class Midi_note : public Midi_channel_item
{
public:
Byte dynamic_byte_;
};
-/**
- Turn a note off
-*/
class Midi_note_off : public Midi_note
{
public:
int number_;
DECLARE_CLASSNAME(Midi_track);
- /*
- Compensate for starting grace notes.
- */
vector<Midi_event*> events_;
Midi_track ();
Midi_stream (string file_name_string);
~Midi_stream ();
- Midi_stream &operator << (string str);
- Midi_stream &operator << (Midi_item const &midi_c_r);
- Midi_stream &operator << (int i);
+ void write (string);
+ void write (Midi_item const &);
+ void write (int);
void open ();
struct Midi_note_event : PQueue_ent<int, Midi_note *>
{
- bool ignore_b_;
+ bool ignore_;
Midi_note_event ();
};
void do_start_note (Midi_note *note);
void do_stop_notes (int);
void output_event (int, Midi_item *l);
-
+
int channel_;
Midi_track *track_;
Audio_staff *staff_;
PQueue<Midi_note_event> stop_note_queue;
int last_tick_;
- vector<Midi_item*> midi_items_;
};
#endif // MIDI_WALKER_HH
/*
- midi-item.cc -- implement Midi items.
+ midi-item.cc -- implement MIDI items.
source file of the GNU LilyPond music typesetter
{
}
-Midi_channel_item::~Midi_channel_item ()
-{
- channel_ = 0;
-}
-
Midi_channel_item::Midi_channel_item ()
{
channel_ = 0;
Midi_track::data_string () const
{
string str = Midi_chunk::data_string ();
- if (do_midi_debugging_global)
- str += "\n";
for (vector<Midi_event*>::const_iterator i (events_.begin());
i != events_.end(); i ++)
{
str += (*i)->to_string ();
- if (do_midi_debugging_global)
- str += "\n";
}
return str;
}
fclose (out_file_);
}
-Midi_stream &
-Midi_stream::operator << (string str)
+void
+Midi_stream::write (string str)
{
size_t sz = sizeof (Byte);
size_t n = str.length ();
if (written != sz * n)
warning (_ ("cannot write to file: `%s'"));
-
- return *this;
}
-Midi_stream &
-Midi_stream::operator << (Midi_item const &midi_c_r)
+void
+Midi_stream::write (Midi_item const &midi)
{
- string str = midi_c_r.to_string ();
-
- // ugh, should have separate debugging output with Midi*::print routines
- if (do_midi_debugging_global)
- {
- str = String_convert::bin2hex (str) + "\n";
- for (ssize i = str.find ("0a"); i != NPOS; i = str.find ("0a"))
- {
- str[i] = '\n';
- str[i + 1] = '\t';
- }
- }
+ string str = midi.to_string ();
- return operator << (str);
+ return write (str);
}
-Midi_stream &
-Midi_stream::operator << (int i)
+void
+Midi_stream::write (int i)
{
- // output binary string ourselves
- *this << Midi_item::i2varint_string (i);
- return *this;
+ write (Midi_item::i2varint_string (i));
}
Midi_note_event::Midi_note_event ()
{
- ignore_b_ = false;
+ ignore_ = false;
}
int
Midi_walker::~Midi_walker ()
{
- do_stop_notes (last_tick_ + 384);
-
- for (vsize i = 0; i < midi_items_.size (); i++)
- delete midi_items_[i];
+ do_stop_notes (INT_MAX);
}
+
/**
Find out if start_note event is needed, and do it if needed.
*/
{
/* let stopnote in queue be ignored,
new stop note wins */
- stop_note_queue[i].ignore_b_ = true;
+ stop_note_queue[i].ignore_ = true;
+
/* don't replay start note, */
play_start = false;
break;
if (play_start)
output_event (ptr->audio_column_->ticks (), note);
-
- midi_items_.push_back (e.val);
}
}
while (stop_note_queue.size () && stop_note_queue.front ().key <= max_ticks)
{
Midi_note_event e = stop_note_queue.get ();
- if (e.ignore_b_)
+ if (e.ignore_)
{
delete e.val;
continue;
}
}
-/**
- Advance the track to #now#, output the item, and adjust current "moment".
-*/
void
Midi_walker::output_event (int now_ticks, Midi_item *l)
{
if (Midi_channel_item *mci = dynamic_cast<Midi_channel_item*> (midi))
mci->channel_ = channel_;
- //midi->channel_ = track_->number_;
if (Midi_note *note = dynamic_cast<Midi_note *> (midi))
{
if (note->audio_->length_mom_.to_bool ())
}
else
output_event (audio->audio_column_->ticks (), midi);
-
-
- midi_items_.push_back (midi);
}
}
{
int tracks_ = audio_staffs_.size ();
- midi_stream << Midi_header (1, tracks_, 384);
+ midi_stream.write (Midi_header (1, tracks_, 384));
if (be_verbose_global)
progress_indication (_ ("Track...") + " ");