]> git.donarmstrong.com Git - lilypond.git/commitdiff
partial: 0.0.38.jcn
authorJan Nieuwenhuizen <janneke@gnu.org>
Mon, 3 Mar 1997 12:09:34 +0000 (13:09 +0100)
committerJan Nieuwenhuizen <janneke@gnu.org>
Mon, 3 Mar 1997 12:09:34 +0000 (13:09 +0100)
16 files changed:
hdr/lyric-item.hh [new file with mode: 0644]
hdr/lyricitem.hh [deleted file]
hdr/midi-def.hh [new file with mode: 0644]
hdr/midi-item.hh [new file with mode: 0644]
hdr/midi-stream.hh [new file with mode: 0644]
hdr/mididef.hh [deleted file]
hdr/midiitem.hh [deleted file]
hdr/midistream.hh [deleted file]
hdr/source-file.hh [new file with mode: 0644]
hdr/sourcefile.hh [deleted file]
src/midi-def.cc [new file with mode: 0644]
src/midi-item.cc [new file with mode: 0644]
src/midi-stream.cc [new file with mode: 0644]
src/mididef.cc [deleted file]
src/midiitem.cc [deleted file]
src/midistream.cc [deleted file]

diff --git a/hdr/lyric-item.hh b/hdr/lyric-item.hh
new file mode 100644 (file)
index 0000000..dfbaf98
--- /dev/null
@@ -0,0 +1,19 @@
+//
+//  lyric-item.hh -- part of LilyPond
+//
+//  copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#ifndef LYRIC_ITEM_HH
+#define LYRIC_ITEM_HH
+
+#include "textitem.hh"
+  
+struct Lyric_item : Text_item {
+    /* *************** */
+    Lyric_item(Lyric_req* lreq_l, int voice_count_i);
+    virtual void do_pre_processing();    
+};
+
+
+#endif // LYRIC_ITEM_HH //
+
diff --git a/hdr/lyricitem.hh b/hdr/lyricitem.hh
deleted file mode 100644 (file)
index 46873d8..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-//
-//  lyricitem.hh -- part of LilyPond
-//
-//  copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#ifndef LYRIC_ITEM_HH
-#define LYRIC_ITEM_HH
-
-#include "textitem.hh"
-  
-struct Lyric_item : Text_item {
-    /* *************** */
-    Lyric_item(Lyric_req* lreq_l, int voice_count_i);
-    virtual void do_pre_processing();    
-};
-
-
-#endif // LYRIC_ITEM_HH //
-
diff --git a/hdr/midi-def.hh b/hdr/midi-def.hh
new file mode 100644 (file)
index 0000000..7a559ad
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+  midi-def.hh -- declare 
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
+*/
+
+
+#ifndef MIDIDEF_HH
+#define MIDIDEF_HH
+#include "proto.hh"
+#include "real.hh"
+#include "string.hh"
+#include "moment.hh"
+
+
+/** 
+ */
+struct Midi_def {
+    /// output file name
+    String outfile_str_;
+
+    /// duration of whole note
+    Real whole_seconds_f_;
+
+    Midi_def();
+    Midi_def(Midi_def const& midi_c_r);
+    ~Midi_def();
+
+    Real duration_to_seconds_f(Moment);
+    int get_tempo_i( Moment moment );
+    void set_tempo( Moment moment, int count_per_minute_i );
+    void print() const;
+};
+
+#endif // MIDIDEF_HH //
+
diff --git a/hdr/midi-item.hh b/hdr/midi-item.hh
new file mode 100644 (file)
index 0000000..6688e95
--- /dev/null
@@ -0,0 +1,85 @@
+//
+//  midi-item.hh -- part of LilyPond
+//
+//  copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#ifndef MIDI_ITEM_HH
+#define MIDI_ITEM_HH
+#include "string.hh"
+#include "proto.hh"
+
+struct Midi_item {
+    /* *************** */
+    static String i2varint_str( int i );
+    virtual void output_midi( Midi_stream& midi_stream_r );
+    virtual String str() = 0;
+};
+
+struct Midi_note : public Midi_item {
+    /* *************** */
+    int const c0_pitch_i_c_ = 60;
+    Byte dynamic_byte_;
+
+    /**
+      Generate a note-event on a channel pitch.
+
+      @param #melreq_l# is the pitch. 
+     */
+    Midi_note( Melodic_req* melreq_l, int channel_i, bool on_b );
+
+    virtual String str();
+
+    int channel_i_;
+    int on_b_;
+    int pitch_i_;
+};
+
+struct Midi_duration : public Midi_item {
+    /* *************** */
+    Midi_duration( Real seconds_f );
+
+    virtual String str();
+
+    Real seconds_f_;
+};
+
+struct Midi_chunk : Midi_item {
+    /* *************** */
+    Midi_chunk();
+
+    void add( String str );
+    void set( String header_str, String data_str, String footer_str );
+    virtual String str();
+
+private:
+    String data_str_;
+    String footer_str_;
+    String header_str_;
+};
+
+struct Midi_header : Midi_chunk {
+    /* *************** */
+    Midi_header( int format_i, int tracks_i, int clocks_per_4_i );
+};
+
+struct Midi_tempo : Midi_item {
+    /* *************** */
+    Midi_tempo( int tempo_i );
+
+    virtual String str();
+
+    int tempo_i_;
+};
+
+struct Midi_track : Midi_chunk {
+    /* *************** */
+    int number_i_;
+    Midi_track( int number_i );
+
+    void add( int delta_time_i, String event );
+//     void add( Moment delta_time_moment, Midi_item& mitem_r );
+    void add( Moment delta_time_moment, Midi_item* mitem_l );
+};
+
+#endif // MIDI_ITEM_HH //
+
diff --git a/hdr/midi-stream.hh b/hdr/midi-stream.hh
new file mode 100644 (file)
index 0000000..6946bfd
--- /dev/null
@@ -0,0 +1,32 @@
+//
+//  midi-stream.hh -- part of LilyPond
+//
+//  copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#ifndef MIDI_STREAM_HH
+#define MIDI_STREAM_HH
+
+#include <iostream.h>
+#include "string.hh"
+
+/// Midi output
+struct Midi_stream {
+    ostream* os_p_;
+    String filename_str_;
+    int clocks_per_4_i_;
+    int tracks_i_;
+    
+    Midi_stream( String filename_str, int tracks_i, int clocks_per_4_i_ );
+    ~Midi_stream();
+
+    Midi_stream& operator <<( String str );
+    Midi_stream& operator <<( Midi_item& mitem_r );
+    Midi_stream& operator <<( int i );
+
+    void header();
+    void open();
+
+//private:
+//    Midi_stream(Midi_stream const&);
+};
+#endif // MIDI_STREAM_HH //
diff --git a/hdr/mididef.hh b/hdr/mididef.hh
deleted file mode 100644 (file)
index 9a24fa5..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
-  mididef.hh -- declare 
-
-  source file of the LilyPond music typesetter
-
-  (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
-*/
-
-
-#ifndef MIDIDEF_HH
-#define MIDIDEF_HH
-#include "proto.hh"
-#include "real.hh"
-#include "string.hh"
-#include "moment.hh"
-
-
-/** 
- */
-struct Midi_def {
-    /// output file name
-    String outfile_str_;
-
-    /// duration of whole note
-    Real whole_seconds_f_;
-
-    Midi_def();
-    Midi_def(Midi_def const& midi_c_r);
-    ~Midi_def();
-
-    Real duration_to_seconds_f(Moment);
-    int get_tempo_i( Moment moment );
-    void set_tempo( Moment moment, int count_per_minute_i );
-    void print() const;
-};
-
-#endif // MIDIDEF_HH //
-
diff --git a/hdr/midiitem.hh b/hdr/midiitem.hh
deleted file mode 100644 (file)
index f4b14aa..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-//
-//  midiitem.hh -- part of LilyPond
-//
-//  copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#ifndef MIDI_ITEM_HH
-#define MIDI_ITEM_HH
-#include "string.hh"
-#include "proto.hh"
-
-struct Midi_item {
-    /* *************** */
-    static String i2varint_str( int i );
-    virtual void output_midi( Midi_stream& midi_stream_r );
-    virtual String str() = 0;
-};
-
-struct Midi_note : public Midi_item {
-    /* *************** */
-    int const c0_pitch_i_c_ = 60;
-    Byte dynamic_byte_;
-
-    /**
-      Generate a note-event on a channel pitch.
-
-      @param #melreq_l# is the pitch. 
-     */
-    Midi_note( Melodic_req* melreq_l, int channel_i, bool on_b );
-
-    virtual String str();
-
-    int channel_i_;
-    int on_b_;
-    int pitch_i_;
-};
-
-struct Midi_duration : public Midi_item {
-    /* *************** */
-    Midi_duration( Real seconds_f );
-
-    virtual String str();
-
-    Real seconds_f_;
-};
-
-struct Midi_chunk : Midi_item {
-    /* *************** */
-    Midi_chunk();
-
-    void add( String str );
-    void set( String header_str, String data_str, String footer_str );
-    virtual String str();
-
-private:
-    String data_str_;
-    String footer_str_;
-    String header_str_;
-};
-
-struct Midi_header : Midi_chunk {
-    /* *************** */
-    Midi_header( int format_i, int tracks_i, int clocks_per_4_i );
-};
-
-struct Midi_tempo : Midi_item {
-    /* *************** */
-    Midi_tempo( int tempo_i );
-
-    virtual String str();
-
-    int tempo_i_;
-};
-
-struct Midi_track : Midi_chunk {
-    /* *************** */
-    int number_i_;
-    Midi_track( int number_i );
-
-    void add( int delta_time_i, String event );
-//     void add( Moment delta_time_moment, Midi_item& mitem_r );
-    void add( Moment delta_time_moment, Midi_item* mitem_l );
-};
-
-#endif // MIDI_ITEM_HH //
-
diff --git a/hdr/midistream.hh b/hdr/midistream.hh
deleted file mode 100644 (file)
index 769cd23..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-//
-//  midistream.hh -- part of LilyPond
-//
-//  copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#ifndef MIDI_STREAM_HH
-#define MIDI_STREAM_HH
-
-#include <iostream.h>
-#include "string.hh"
-
-/// Midi output
-struct Midi_stream {
-    ostream* os_p_;
-    String filename_str_;
-    int clocks_per_4_i_;
-    int tracks_i_;
-    
-    Midi_stream( String filename_str, int tracks_i, int clocks_per_4_i_ );
-    ~Midi_stream();
-
-    Midi_stream& operator <<( String str );
-    Midi_stream& operator <<( Midi_item& mitem_r );
-    Midi_stream& operator <<( int i );
-
-    void header();
-    void open();
-
-//private:
-//    Midi_stream(Midi_stream const&);
-};
-#endif // MIDI_STREAM_HH //
diff --git a/hdr/source-file.hh b/hdr/source-file.hh
new file mode 100644 (file)
index 0000000..7f7168e
--- /dev/null
@@ -0,0 +1,40 @@
+//
+//  source-file.hh -- declare Source_file
+//
+//  copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#ifndef SOURCE_FILE_HH
+#define SOURCE_FILE_HH
+
+/// class for reading and mapping a file. 
+class Source_file
+{
+public:
+    /** Ugh! filename gets changed! The path to the opened file may
+       change, since it might be searched in multiple directories.  */
+    Source_file( String& filename_str_r );
+    virtual ~Source_file();
+
+    char const* ch_c_l();
+    virtual String error_str( char const* pos_ch_c_l );
+    istream* istream_l();
+    bool in_b( char const* pos_ch_c_l );
+    off_t length_off();
+    virtual int line_i( char const* pos_ch_c_l );
+    String name_str();
+    String file_line_no_str( char const* ch_c_l );
+
+private:
+    void close();
+    void map();
+    void open();
+    void unmap();
+
+    istream* istream_p_;
+    int fildes_i_;
+    String name_str_;
+    off_t size_off_;
+    caddr_t data_caddr_;
+};
+
+#endif // SOURCE_FILE_HH //
diff --git a/hdr/sourcefile.hh b/hdr/sourcefile.hh
deleted file mode 100644 (file)
index 251efd5..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-//
-//  sourcefile.hh -- declare Source_file
-//
-//  copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#ifndef SOURCE_FILE_HH
-#define SOURCE_FILE_HH
-
-/// class for reading and mapping a file. 
-class Source_file
-{
-public:
-    /**
-      @return path to opened file.
-     */
-    // jcn: ugh! filename gets changed!, why?
-    Source_file( String& filename_str );
-    virtual ~Source_file();
-
-    char const* ch_c_l();
-    virtual String error_str( char const* pos_ch_c_l );
-    istream* istream_l();
-    bool in_b( char const* pos_ch_c_l );
-    off_t length_off();
-    virtual int line_i( char const* pos_ch_c_l );
-    String name_str();
-    String file_line_no_str( char const* ch_c_l );
-
-private:
-    void close();
-    void map();
-    void open();
-    void unmap();
-
-    istream* istream_p_;
-    int fildes_i_;
-    String name_str_;
-    off_t size_off_;
-    caddr_t data_caddr_;
-};
-
-#endif // SOURCE_FILE_HH //
diff --git a/src/midi-def.cc b/src/midi-def.cc
new file mode 100644 (file)
index 0000000..5430823
--- /dev/null
@@ -0,0 +1,64 @@
+//
+// midi-def.cc -- implement midi output
+//
+// source file of the LilyPond music typesetter
+//
+// (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#include <math.h>
+#include "misc.hh"
+#include "midi-def.hh"
+#include "debug.hh"
+
+// classes, alphasorted
+//     statics
+//     constructors
+//     destructor
+//     routines, alphasorted
+
+Midi_def::Midi_def()
+{
+    set_tempo( Moment( 1, 4 ), 60 );
+    outfile_str_ = "lelie.midi"; 
+}
+
+Midi_def::Midi_def( Midi_def const& midi_c_r )
+{
+    whole_seconds_f_ = midi_c_r.whole_seconds_f_;
+    outfile_str_ = midi_c_r.outfile_str_;
+}
+
+Midi_def::~Midi_def()
+{
+}
+
+Real
+Midi_def::duration_to_seconds_f( Moment moment )
+{
+    if (!moment)
+       return 0;
+    
+    return whole_seconds_f_ * moment;
+}
+
+int
+Midi_def::get_tempo_i( Moment moment )
+{
+    return Moment( whole_seconds_f_ ) * Moment( 60 ) * moment;
+}
+
+void
+Midi_def::print() const
+{
+#ifndef NPRINT
+    mtor << "Midi {4/min: " << Real( 60 ) / ( whole_seconds_f_ * 4 );
+    mtor << "out: " << outfile_str_;
+    mtor << "}\n";
+#endif
+}
+
+void
+Midi_def::set_tempo( Moment moment, int count_per_minute_i )
+{
+    whole_seconds_f_ = Moment( count_per_minute_i ) / Moment( 60 ) / moment;
+}
diff --git a/src/midi-item.cc b/src/midi-item.cc
new file mode 100644 (file)
index 0000000..9d121cf
--- /dev/null
@@ -0,0 +1,196 @@
+//
+// midi-item.cc
+//
+// source file of the LilyPond music typesetter
+//
+// (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#include <limits.h>
+#include "plist.hh"
+#include "pcol.hh"
+#include "debug.hh"
+#include "misc.hh"
+#include "request.hh"
+#include "musicalrequest.hh"
+#include "voice.hh"
+#include "midi-item.hh"
+#include "midi-stream.hh"
+#include "string-convert.hh"
+
+Midi_chunk::Midi_chunk()
+{
+}
+
+void
+Midi_chunk::add( String str )
+{
+    data_str_ += str;
+}
+
+void
+Midi_chunk::set( String header_str, String data_str, String footer_str )
+{
+    data_str_ = data_str;
+    footer_str_ = footer_str;
+    header_str_ = header_str;
+}
+  
+String
+Midi_chunk::str()
+{
+    String str = header_str_;
+    String length_str = String_convert::i2hex_str( data_str_.length_i() + footer_str_.length_i(), 8, '0' );
+    length_str = String_convert::hex2bin_str( length_str );
+    str += length_str;
+    str += data_str_;
+    str += footer_str_;
+    return str;
+}
+
+Midi_duration::Midi_duration( Real seconds_f )
+{
+    seconds_f_ = seconds_f;
+}
+
+String
+Midi_duration::str()
+{
+    return String( "<duration: " ) + String( seconds_f_ ) + ">";
+}
+
+Midi_header::Midi_header( int format_i, int tracks_i, int clocks_per_4_i )
+{
+    String str;
+       
+    String format_str = String_convert::i2hex_str( format_i, 4, '0' );
+    str += String_convert::hex2bin_str( format_str );
+       
+    String tracks_str = String_convert::i2hex_str( tracks_i, 4, '0' );
+    str += String_convert::hex2bin_str( tracks_str );
+
+    String tempo_str = String_convert::i2hex_str( clocks_per_4_i, 4, '0' );
+    str += String_convert::hex2bin_str( tempo_str );
+
+    set( "MThd", str, "" );
+}
+
+String
+Midi_item::i2varint_str( int i )
+{
+    int buffer_i = i & 0x7f;
+    while ( (i >>= 7) > 0 ) {
+       buffer_i <<= 8;
+       buffer_i |= 0x80;
+       buffer_i += (i & 0x7f);
+    }
+
+    String str;
+    while ( 1 ) {
+       str += (char)buffer_i;
+       if ( buffer_i & 0x80 )
+           buffer_i >>= 8;
+       else
+           break;
+    }
+    return str;
+}
+
+void 
+Midi_item::output_midi( Midi_stream& midi_stream_r )
+{
+    midi_stream_r << str();
+}
+
+
+Midi_note::Midi_note( Melodic_req* melreq_l, int channel_i, bool on_bo  )
+{
+    assert(melreq_l);
+    pitch_i_ = melreq_l->pitch() + c0_pitch_i_c_;   
+    channel_i_ = channel_i;
+
+    // poor man-s staff dynamics:
+    dynamic_byte_ =  (melreq_l)? 0x64 - 0x10 * channel_i_:0;
+    on_b_ = on_bo;
+}
+
+String
+Midi_note::str()
+{
+    if ( pitch_i_ != INT_MAX ) {
+       Byte status_byte = ( on_b_ ? 0x90 : 0x80 ) + channel_i_;
+       String str = String( (char)status_byte );
+       str += (char)pitch_i_;
+       // poor man-s staff dynamics:
+       str += (char)dynamic_byte_;
+       return str;
+    }
+    return String( "" );
+}
+
+Midi_tempo::Midi_tempo( int tempo_i )
+{
+    tempo_i_ = tempo_i;
+}
+
+String
+Midi_tempo::str()
+{
+    int useconds_per_4_i = 60 * (int)1e6 / tempo_i_;
+    String str = "ff5103";
+    str += String_convert::i2hex_str( useconds_per_4_i, 6, '0' );
+    return String_convert::hex2bin_str( str );
+}
+
+Midi_track::Midi_track( int number_i )
+{
+//                4D 54 72 6B     MTrk
+//                00 00 00 3B     chunk length (59)
+//        00      FF 58 04 04 02 18 08    time signature
+//        00      FF 51 03 07 A1 20       tempo
+// FF 59 02 sf mi  Key Signature
+//         sf = -7:  7 flats
+//         sf = -1:  1 flat
+//         sf = 0:  key of C
+//         sf = 1:  1 sharp
+//         sf = 7: 7 sharps
+//         mi = 0:  major key
+//         mi = 1:  minor key
+
+    number_i_ = number_i;
+       
+    char const* data_ch_c_l = "00" "ff58" "0404" "0218" "08"
+//     "00" "ff51" "0307" "a120"
+// why a key at all, in midi?
+// key: C
+       "00" "ff59" "02" "00" "00"
+// key: F (scsii-menuetto)
+//                               "00" "ff59" "02" "ff" "00"
+       ;
+
+    String data_str;
+    // only for format 0 (currently using format 1)?
+    data_str += String_convert::hex2bin_str( data_ch_c_l );
+
+    char const* footer_ch_c_l = "00" "ff2f" "00";
+    String footer_str = String_convert::hex2bin_str( footer_ch_c_l );
+
+    set( "MTrk", data_str, footer_str );
+}
+
+void 
+Midi_track::add( int delta_time_i, String event_str )
+{
+    assert(delta_time_i >= 0);
+    Midi_chunk::add( i2varint_str( delta_time_i ) + event_str );
+}
+
+void 
+Midi_track::add( Moment delta_time_moment, Midi_item* mitem_l )
+{
+    // use convention of 384 clocks per 4
+    // use Duration_convert
+    int delta_time_i = delta_time_moment * Moment( 384 ) / Moment( 1, 4 );
+    add( delta_time_i, mitem_l->str() );
+}
+
diff --git a/src/midi-stream.cc b/src/midi-stream.cc
new file mode 100644 (file)
index 0000000..3630831
--- /dev/null
@@ -0,0 +1,89 @@
+//
+// midi-stream.cc
+//
+// source file of the LilyPond music typesetter
+//
+// (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#include <fstream.h>
+#include <time.h>
+#include "main.hh"
+#include "misc.hh"
+#include "midi-item.hh"
+#include "midi-stream.hh"
+#include "debug.hh"
+#include "string-convert.hh"
+
+Midi_stream::Midi_stream( String filename_str, int tracks_i, int clocks_per_4_i ) 
+{
+    filename_str_ = filename_str;
+    tracks_i_ = tracks_i;
+    clocks_per_4_i_ = clocks_per_4_i;
+    os_p_ = 0;
+    open();
+    header();
+}
+
+Midi_stream::~Midi_stream()
+{
+    delete os_p_;
+}
+
+Midi_stream&
+Midi_stream::operator <<( String str )
+{
+    // still debugging...
+    if ( check_debug )
+       str = String_convert::bin2hex_str( str );
+    // string now 1.0.26-2 handles binary streaming
+    *os_p_ << str;
+    return *this;
+}
+
+Midi_stream&
+Midi_stream::operator <<( Midi_item& mitem_r )
+{
+    mitem_r.output_midi( *this );
+    if ( check_debug )
+        *os_p_ << "\n";
+    return *this;
+}
+
+Midi_stream&
+Midi_stream::operator <<( int i )
+{
+    // output binary string ourselves
+    *this << Midi_item::i2varint_str( i );
+    return *this;
+}
+
+void
+Midi_stream::header()
+{
+//    *os_p_ << "% Creator: " << get_version();
+//    *os_p_ << "% Automatically generated, at ";
+//    time_t t(time(0));
+//    *os_p_ << ctime(&t);
+
+//                4D 54 68 64     MThd
+//    String str = "MThd";
+//                00 00 00 06     chunk length
+//                00 01   format 1
+//                00 01   one track
+//                00 60   96 per quarter-note
+
+//    char const ch_c_l = "0000" "0006" "0001" "0001" "0060";
+//    str += String_convert::hex2bin_str( ch_c_l );
+//    *os_p_ << str;
+
+//      *this << Midi_header( 1, 1, tempo_i_ );
+      *this << Midi_header( 1, tracks_i_, clocks_per_4_i_ );
+}
+
+void
+Midi_stream::open()
+{
+    os_p_ = new ofstream( filename_str_ );
+    if ( !*os_p_ )
+       error ("can't open `" + filename_str_ + "\'" );
+}
diff --git a/src/mididef.cc b/src/mididef.cc
deleted file mode 100644 (file)
index 2c7bf7a..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-//
-// mididef.cc -- implement midi output
-//
-// source file of the LilyPond music typesetter
-//
-// (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#include <math.h>
-#include "misc.hh"
-#include "mididef.hh"
-#include "debug.hh"
-
-// classes, alphasorted
-//     statics
-//     constructors
-//     destructor
-//     routines, alphasorted
-
-Midi_def::Midi_def()
-{
-    set_tempo( Moment( 1, 4 ), 60 );
-    outfile_str_ = "lelie.midi"; 
-}
-
-Midi_def::Midi_def( Midi_def const& midi_c_r )
-{
-    whole_seconds_f_ = midi_c_r.whole_seconds_f_;
-    outfile_str_ = midi_c_r.outfile_str_;
-}
-
-Midi_def::~Midi_def()
-{
-}
-
-Real
-Midi_def::duration_to_seconds_f( Moment moment )
-{
-    if (!moment)
-       return 0;
-    
-    return whole_seconds_f_ * moment;
-}
-
-int
-Midi_def::get_tempo_i( Moment moment )
-{
-    return Moment( whole_seconds_f_ ) * Moment( 60 ) * moment;
-}
-
-void
-Midi_def::print() const
-{
-#ifndef NPRINT
-    mtor << "Midi {4/min: " << Real( 60 ) / ( whole_seconds_f_ * 4 );
-    mtor << "out: " << outfile_str_;
-    mtor << "}\n";
-#endif
-}
-
-void
-Midi_def::set_tempo( Moment moment, int count_per_minute_i )
-{
-    whole_seconds_f_ = Moment( count_per_minute_i ) / Moment( 60 ) / moment;
-}
diff --git a/src/midiitem.cc b/src/midiitem.cc
deleted file mode 100644 (file)
index c57f9ff..0000000
+++ /dev/null
@@ -1,195 +0,0 @@
-//
-// midiitem.cc
-//
-// source file of the LilyPond music typesetter
-//
-// (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#include <limits.h>
-#include "plist.hh"
-#include "pcol.hh"
-#include "debug.hh"
-#include "misc.hh"
-#include "request.hh"
-#include "musicalrequest.hh"
-#include "voice.hh"
-#include "midiitem.hh"
-#include "midistream.hh"
-
-Midi_chunk::Midi_chunk()
-{
-}
-
-void
-Midi_chunk::add( String str )
-{
-    data_str_ += str;
-}
-
-void
-Midi_chunk::set( String header_str, String data_str, String footer_str )
-{
-    data_str_ = data_str;
-    footer_str_ = footer_str;
-    header_str_ = header_str;
-}
-  
-String
-Midi_chunk::str()
-{
-    String str = header_str_;
-    String length_str = String_convert::i2hex_str( data_str_.length_i() + footer_str_.length_i(), 8, '0' );
-    length_str = String_convert::hex2bin_str( length_str );
-    str += length_str;
-    str += data_str_;
-    str += footer_str_;
-    return str;
-}
-
-Midi_duration::Midi_duration( Real seconds_f )
-{
-    seconds_f_ = seconds_f;
-}
-
-String
-Midi_duration::str()
-{
-    return String( "<duration: " ) + String( seconds_f_ ) + ">";
-}
-
-Midi_header::Midi_header( int format_i, int tracks_i, int clocks_per_4_i )
-{
-    String str;
-       
-    String format_str = String_convert::i2hex_str( format_i, 4, '0' );
-    str += String_convert::hex2bin_str( format_str );
-       
-    String tracks_str = String_convert::i2hex_str( tracks_i, 4, '0' );
-    str += String_convert::hex2bin_str( tracks_str );
-
-    String tempo_str = String_convert::i2hex_str( clocks_per_4_i, 4, '0' );
-    str += String_convert::hex2bin_str( tempo_str );
-
-    set( "MThd", str, "" );
-}
-
-String
-Midi_item::i2varint_str( int i )
-{
-    int buffer_i = i & 0x7f;
-    while ( (i >>= 7) > 0 ) {
-       buffer_i <<= 8;
-       buffer_i |= 0x80;
-       buffer_i += (i & 0x7f);
-    }
-
-    String str;
-    while ( 1 ) {
-       str += (char)buffer_i;
-       if ( buffer_i & 0x80 )
-           buffer_i >>= 8;
-       else
-           break;
-    }
-    return str;
-}
-
-void 
-Midi_item::output_midi( Midi_stream& midi_stream_r )
-{
-    midi_stream_r << str();
-}
-
-
-Midi_note::Midi_note( Melodic_req* melreq_l, int channel_i, bool on_bo  )
-{
-    assert(melreq_l);
-    pitch_i_ = melreq_l->pitch() + c0_pitch_i_c_;   
-    channel_i_ = channel_i;
-
-    // poor man-s staff dynamics:
-    dynamic_byte_ =  (melreq_l)? 0x64 - 0x10 * channel_i_:0;
-    on_b_ = on_bo;
-}
-
-String
-Midi_note::str()
-{
-    if ( pitch_i_ != INT_MAX ) {
-       Byte status_byte = ( on_b_ ? 0x90 : 0x80 ) + channel_i_;
-       String str = String( (char)status_byte );
-       str += (char)pitch_i_;
-       // poor man-s staff dynamics:
-       str += (char)dynamic_byte_;
-       return str;
-    }
-    return String( "" );
-}
-
-Midi_tempo::Midi_tempo( int tempo_i )
-{
-    tempo_i_ = tempo_i;
-}
-
-String
-Midi_tempo::str()
-{
-    int useconds_per_4_i = 60 * (int)1e6 / tempo_i_;
-    String str = "ff5103";
-    str += String_convert::i2hex_str( useconds_per_4_i, 6, '0' );
-    return String_convert::hex2bin_str( str );
-}
-
-Midi_track::Midi_track( int number_i )
-{
-//                4D 54 72 6B     MTrk
-//                00 00 00 3B     chunk length (59)
-//        00      FF 58 04 04 02 18 08    time signature
-//        00      FF 51 03 07 A1 20       tempo
-// FF 59 02 sf mi  Key Signature
-//         sf = -7:  7 flats
-//         sf = -1:  1 flat
-//         sf = 0:  key of C
-//         sf = 1:  1 sharp
-//         sf = 7: 7 sharps
-//         mi = 0:  major key
-//         mi = 1:  minor key
-
-    number_i_ = number_i;
-       
-    char const* data_ch_c_l = "00" "ff58" "0404" "0218" "08"
-//     "00" "ff51" "0307" "a120"
-// why a key at all, in midi?
-// key: C
-       "00" "ff59" "02" "00" "00"
-// key: F (scsii-menuetto)
-//                               "00" "ff59" "02" "ff" "00"
-       ;
-
-    String data_str;
-    // only for format 0 (currently using format 1)?
-    data_str += String_convert::hex2bin_str( data_ch_c_l );
-
-    char const* footer_ch_c_l = "00" "ff2f" "00";
-    String footer_str = String_convert::hex2bin_str( footer_ch_c_l );
-
-    set( "MTrk", data_str, footer_str );
-}
-
-void 
-Midi_track::add( int delta_time_i, String event_str )
-{
-    assert(delta_time_i >= 0);
-    Midi_chunk::add( i2varint_str( delta_time_i ) + event_str );
-}
-
-void 
-Midi_track::add( Moment delta_time_moment, Midi_item* mitem_l )
-{
-    // use convention of 384 clocks per 4
-    // use Duration_convert
-    int delta_time_i = delta_time_moment * Moment( 384 ) / Moment( 1, 4 );
-    add( delta_time_i, mitem_l->str() );
-}
-
diff --git a/src/midistream.cc b/src/midistream.cc
deleted file mode 100644 (file)
index f561e0b..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-//
-// midistream.cc
-//
-// source file of the LilyPond music typesetter
-//
-// (c) 1997 Jan Nieuwenhuizen <jan@digicash.com>
-
-#include <fstream.h>
-#include <time.h>
-#include "main.hh"
-#include "misc.hh"
-#include "midiitem.hh"
-#include "midistream.hh"
-#include "debug.hh"
-
-Midi_stream::Midi_stream( String filename_str, int tracks_i, int clocks_per_4_i ) 
-{
-    filename_str_ = filename_str;
-    tracks_i_ = tracks_i;
-    clocks_per_4_i_ = clocks_per_4_i;
-    os_p_ = 0;
-    open();
-    header();
-}
-
-Midi_stream::~Midi_stream()
-{
-    delete os_p_;
-}
-
-Midi_stream&
-Midi_stream::operator <<( String str )
-{
-    // still debugging...
-    if ( check_debug )
-       str = String_convert::bin2hex_str( str );
-    // string now 1.0.26-2 handles binary streaming
-    *os_p_ << str;
-    return *this;
-}
-
-Midi_stream&
-Midi_stream::operator <<( Midi_item& mitem_r )
-{
-    mitem_r.output_midi( *this );
-    if ( check_debug )
-        *os_p_ << "\n";
-    return *this;
-}
-
-Midi_stream&
-Midi_stream::operator <<( int i )
-{
-    // output binary string ourselves
-    *this << Midi_item::i2varint_str( i );
-    return *this;
-}
-
-void
-Midi_stream::header()
-{
-//    *os_p_ << "% Creator: " << get_version();
-//    *os_p_ << "% Automatically generated, at ";
-//    time_t t(time(0));
-//    *os_p_ << ctime(&t);
-
-//                4D 54 68 64     MThd
-//    String str = "MThd";
-//                00 00 00 06     chunk length
-//                00 01   format 1
-//                00 01   one track
-//                00 60   96 per quarter-note
-
-//    char const ch_c_l = "0000" "0006" "0001" "0001" "0060";
-//    str += String_convert::hex2bin_str( ch_c_l );
-//    *os_p_ << str;
-
-//      *this << Midi_header( 1, 1, tempo_i_ );
-      *this << Midi_header( 1, tracks_i_, clocks_per_4_i_ );
-}
-
-void
-Midi_stream::open()
-{
-    os_p_ = new ofstream( filename_str_ );
-    if ( !*os_p_ )
-       error ("can't open `" + filename_str_ + "\'" );
-}