]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/midi-item.cc
release: 0.0.77.jcn1
[lilypond.git] / lily / midi-item.cc
index 9a63d93e5a0e602d8b707bddbaf4358e79f4997b..2efb36aff1057f6c4e19ae3e37399da1780c1655 100644 (file)
@@ -1,24 +1,37 @@
-//
-// midiitem.cc
-//
-// source file of the LilyPond music typesetter
-//
-// (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
+/*
+  midi-item.cc -- implement various midi items.
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
 
 #include <limits.h>
 #include "proto.hh"
 #include "plist.hh"
-#include "pcol.hh"
+#include "p-col.hh"
 #include "debug.hh"
 #include "misc.hh"
 #include "string.hh"
 #include "string-convert.hh"
 #include "request.hh"
-#include "musicalrequest.hh"
-#include "voice.hh"
+#include "musical-request.hh"
+#include "music-list.hh"
 #include "midi-item.hh"
 #include "midi-stream.hh"
 
+
+IMPLEMENT_IS_TYPE_B(Midi_item);
+IMPLEMENT_IS_TYPE_B1(Midi_key,Midi_item);
+IMPLEMENT_IS_TYPE_B1(Midi_note, Midi_item);
+IMPLEMENT_IS_TYPE_B1(Midi_duration, Midi_item);
+IMPLEMENT_IS_TYPE_B1(Midi_chunk, Midi_item);
+IMPLEMENT_IS_TYPE_B1(Midi_header, Midi_chunk);
+IMPLEMENT_IS_TYPE_B1(Midi_text, Midi_item);
+IMPLEMENT_IS_TYPE_B1(Midi_tempo, Midi_item);
+IMPLEMENT_IS_TYPE_B1(Midi_time, Midi_item);
+IMPLEMENT_IS_TYPE_B1(Midi_track, Midi_chunk);
+
 Midi_chunk::Midi_chunk()
 {
 }
@@ -161,6 +174,24 @@ Midi_tempo::str() const
     return String_convert::hex2bin_str( str );
 }
 
+Midi_time::Midi_time( int num_i, int den_i, int clocks_per_1_i )
+{
+       num_i_ = num_i;
+       den_i_ = den_i;
+       clocks_per_1_i_ = clocks_per_1_i;
+}
+
+String
+Midi_time::str() const
+{
+       String str = "ff5804";
+       str += String_convert::i2hex_str( num_i_, 2, '0' );
+       str += String_convert::i2hex_str( intlog2( den_i_ ) , 2, '0' );
+       str += String_convert::i2hex_str( clocks_per_1_i_, 2, '0' );
+       str += String_convert::i2hex_str( 8, 2, '0' );
+       return String_convert::hex2bin_str( str );
+}
+
 Midi_text::Midi_text( Midi_text::Type type, String text_str )
 {
        type_ = type;
@@ -177,7 +208,7 @@ Midi_text::str() const
        return str;
 }
 
-Midi_track::Midi_track( int number_i )
+Midi_track::Midi_track( )
 {
 //                4D 54 72 6B     MTrk
 //                00 00 00 3B     chunk length (59)
@@ -193,9 +224,10 @@ Midi_track::Midi_track( int number_i )
 //         mi = 0:  major key
 //         mi = 1:  minor key
 
-    number_i_ = number_i;
+    number_i_ = 0;
        
-    char const* data_ch_c_l = "00" "ff58" "0404" "0218" "08"
+    char const* data_ch_C = ""
+//        "00" "ff58" "0404" "0218" "08"
 //     "00" "ff51" "0307" "a120"
 // why a key at all, in midi?
 // key: C
@@ -206,10 +238,10 @@ Midi_track::Midi_track( int number_i )
 
     String data_str;
     // only for format 0 (currently using format 1)?
-    data_str += String_convert::hex2bin_str( data_ch_c_l );
+    data_str += String_convert::hex2bin_str( data_ch_C );
 
-    char const* footer_ch_c_l = "00" "ff2f" "00";
-    String footer_str = String_convert::hex2bin_str( footer_ch_c_l );
+    char const* footer_ch_C = "00" "ff2f" "00";
+    String footer_str = String_convert::hex2bin_str( footer_ch_C );
 
     set( "MTrk", data_str, footer_str );
 }
@@ -217,6 +249,10 @@ Midi_track::Midi_track( int number_i )
 void 
 Midi_track::add( int delta_time_i, String event_str )
 {
+    if ( delta_time_i < 0 ) {
+       cout << String_convert::bin2hex_str( i2varint_str( delta_time_i ) ) << endl;
+       cout << String_convert::bin2hex_str( event_str ) << endl;
+    }
     assert(delta_time_i >= 0);
     Midi_chunk::add( i2varint_str( delta_time_i ) + event_str );
 }