From: fred Date: Sun, 24 Mar 2002 19:56:58 +0000 (+0000) Subject: lilypond-0.1.8 X-Git-Tag: release/1.5.59~3931 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=956b0f8213f230e30f2a1274a861a8326b19e44c;p=lilypond.git lilypond-0.1.8 --- diff --git a/Documentation/lelie_icon.gif b/Documentation/lelie_icon.gif deleted file mode 100644 index 59b6c23680..0000000000 Binary files a/Documentation/lelie_icon.gif and /dev/null differ diff --git a/Documentation/lelie_logo.gif b/Documentation/lelie_logo.gif deleted file mode 100644 index d606099457..0000000000 Binary files a/Documentation/lelie_logo.gif and /dev/null differ diff --git a/mi2mu/include/lily-stream.hh b/mi2mu/include/lily-stream.hh deleted file mode 100644 index 755d19fb55..0000000000 --- a/mi2mu/include/lily-stream.hh +++ /dev/null @@ -1,35 +0,0 @@ -// -// lily-stream.hh -- part of LilyPond -// -// copyright 1997 Jan Nieuwenhuizen - -// should i be named Mudela_stream? - -#ifndef LILY_STREAM_HH -#define LILY_STREAM_HH - -/// Lily output -class Lily_stream { -public: - Lily_stream( String filename_str ); - ~Lily_stream(); - - Lily_stream& operator <<( String str ); - Lily_stream& operator <<( Midi_event& midi_event_r ); - -private: - void header(); - void open(); - void output( String str ); - void output_wrapped( String str ); - - ostream* os_p_; - String filename_str_; - int indent_i_; - int column_i_; - int wrap_column_i_; - bool comment_mode_b_; -}; - -#endif // LILY_STREAM_HH - diff --git a/mi2mu/include/mi2mu.hh b/mi2mu/include/mi2mu.hh deleted file mode 100644 index 7885afd0d2..0000000000 --- a/mi2mu/include/mi2mu.hh +++ /dev/null @@ -1,62 +0,0 @@ -// -// mi2mu.hh -- generic mi2mu include file -// -// copyright 1997 Jan Nieuwenhuizen - -#ifndef M2M_HH -#define M2M_HH - -// yes, i know this hurts the dependency calc, however, -// having includes in headers sucks, and long trial and error -// include lists also suck. -// if you want less dependecies, break lib/exe down in smaller -// modules. - -#include -#include -#include -#include -#include -#include - -#include "mi2mu-proto.hh" -#include "proto.hh" -#include "plist.hh" -#include "warn.hh" -#ifdef mtor -#undef mtor -#endif - -// arrays are 20% faster, but we have no Pointer_array yet -#define MEVENT_LIST // does this work? -#define MVOICE_LIST -#define TCOL_LIST - -#include "string.hh" -#include "string-convert.hh" - -#include "lgetopt.hh" - -#include "moment.hh" -#include "duration-convert.hh" -#include "duration.hh" -#include "source-file.hh" -#include "source.hh" - -// mustn-t do, these get touched! -// #include "fversion.hh" -// #include "version.hh" - -#include "midi-global.hh" - -#include "lily-stream.hh" -#include "midi-event.hh" -#include "midi-score.hh" -#include "midi-track.hh" -#include "midi-voice.hh" -#include "my-midi-lexer.hh" -#include "my-midi-parser.hh" -#include "track-column.hh" - -#endif // M2M_HH - diff --git a/mi2mu/include/midi-event.hh b/mi2mu/include/midi-event.hh deleted file mode 100644 index 928851e808..0000000000 --- a/mi2mu/include/midi-event.hh +++ /dev/null @@ -1,100 +0,0 @@ -// -// midi-event.hh -- declare midi_event -// -// copyright 1997 Jan Nieuwenhuizen - -#ifndef MIDI_EVENT_HH -#define MIDI_EVENT_HH - - -// should these: -// * be Midi_items -// * be Voice_elements/requests -// * get a name-change -// ? - -/// (midi_event) -class Midi_event { -public: - Midi_event(); - - virtual String mudela_str( bool command_mode_bo ) = 0; - void output_mudela( Lily_stream& lily_stream_r, bool command_mode_bo ); - virtual Moment mom(); -}; - -class Midi_key : public Midi_event { -public: - Midi_key( int accidentals_i, int minor_i ); - - String notename_str( int pitch_i ); - virtual String mudela_str( bool command_mode_bo ); - -private: - int accidentals_i_; - int minor_i_; - int key_i_; -}; - -class Midi_note : public Midi_event { -public: -// int const c0_pitch_i_c_ = 60; // huh? - int const c0_pitch_i_c_ = 48; - - Midi_note( String name_str, Duration dur ); - virtual Moment mom(); - virtual String mudela_str( bool command_mode_bo ); - -private: - static bool const simple_plet_b_s = false; - Duration dur_; - String name_str_; -}; - -class Midi_tempo : public Midi_event { -public: - Midi_tempo( int useconds_per_4_i ); - - int get_tempo_i( Moment moment ); - virtual String mudela_str( bool command_mode_bo ); - int useconds_per_4_i(); - -private: - int useconds_per_4_i_; - Real seconds_per_1_f_; -}; - -class Midi_text : public Midi_event { -public: - enum Type { - TEXT = 1, COPYRIGHT, TRACK_NAME, INSTRUMENT_NAME, LYRIC, - MARKER, CUE_POINT - }; - Midi_text( Midi_text::Type type, String str ); - virtual String mudela_str( bool command_mode_bo ); -private: - Type type_; - String text_str_; -}; - -class Midi_time : public Midi_event { -public: - Midi_time( int num_i, int den_i, int division_4_i, int count_32_i ); - - Duration i2_dur( int time_i, int division_1_i ); - int clocks_1_i(); - int den_i(); - int num_i(); - virtual String mudela_str( bool command_mode_bo ); - Moment bar_mom(); - -private: - Real sync_f_; - Duration sync_dur_; - int clocks_1_i_; - int num_i_; - int den_i_; -}; - -#endif // MIDI_EVENT_HH - diff --git a/mi2mu/include/midi-global.hh b/mi2mu/include/midi-global.hh deleted file mode 100644 index 0941232c0d..0000000000 --- a/mi2mu/include/midi-global.hh +++ /dev/null @@ -1,30 +0,0 @@ -// -// midi-global.hh -- declare global (sic) stuff for mi2mu -// -// copyright 1997 Jan Nieuwenhuizen - -#ifndef MIDI_GLOBAL_HH -#define MIDI_GLOBAL_HH - -#include "string.hh" - -#define monitor_p_g &cout -enum Verbose { QUIET_ver, BRIEF_ver, NORMAL_ver, VERBOSE_ver, DEBUG_ver }; -extern Verbose level_ver; -#if 0 // NPRINT - // not what i want, all output goes through tors. - // set verbosity level. - #define tor( threshold ) if ( 0 ) *monitor_p_g -#else - #define tor( threshold ) if ( level_ver >= threshold ) *monitor_p_g -#endif - -extern Sources* source_l_g; -void message( String message_str, char const* context_ch_C ); -void warning( String message_str, char const* context_ch_C ); -void error( String message_str, char const* context_ch_C ); - -String mi2mu_version_str(); - -#endif // MIDI_GLOBAL_HH - diff --git a/mi2mu/include/midi-score.hh b/mi2mu/include/midi-score.hh deleted file mode 100644 index 990d4031ef..0000000000 --- a/mi2mu/include/midi-score.hh +++ /dev/null @@ -1,28 +0,0 @@ -// -// midi-score.hh -- declare midi_score -// -// copyright 1997 Jan Nieuwenhuizen - -#ifndef MIDI_SCORE_HH -#define MIDI_SCORE_HH - -/// (midi_score) -class Midi_score { -public: - Midi_score( int format_i, int tracks_i, int tempo_i ); - ~Midi_score(); - - void add_track( Midi_track* midi_track_p ); - - int output_mudela( String filename_str ); - void process(); - -private: - Pointer_list midi_track_p_list_; - int format_i_; - int tracks_i_; - int tempo_i_; -}; - -#endif // MIDI_SCORE_HH - diff --git a/mi2mu/include/midi-track.hh b/mi2mu/include/midi-track.hh deleted file mode 100644 index 3d654ae3df..0000000000 --- a/mi2mu/include/midi-track.hh +++ /dev/null @@ -1,65 +0,0 @@ -// -// midi-track.hh -- declare midi_track -// -// copyright 1997 Jan Nieuwenhuizen - -#ifndef MIDI_TRACK_HH -#define MIDI_TRACK_HH - -/// (midi_track) -class Midi_track { -public: - Midi_track( int number_i, String copyright_str, String track_name_str, String instrument_str ); - ~Midi_track(); - - void add_event( Moment mom, Midi_event* midi_event_p ); - Moment end_mom(); - String id_str(); - String name_str(); - void output_mudela( Lily_stream& lily_stream_r ); - Moment next_begin_mom( Moment now_mom ); - Moment next_end_mom( Moment now_mom ); - void process(); - void set_tempo( int useconds_i ); - void set_time( int num_i, int den_i, int clocks_i, int count_32_i ); - Track_column* tcol_l( Moment mom ); - - String copyright_str_; - String instrument_str_; - String name_str_; - Midi_tempo* midi_tempo_p_; - Midi_time* midi_time_p_; - int number_i_; - -private: -#ifdef MVOICE_LIST - void add_begin_at( Link_list& open_voices_r, Moment mom ); -#else - void add_begin_at( Array& open_voices_r, Moment mom ); -#endif - int check_begin_bar_i( Moment now_mom, int open_bar_i ); - int check_end_bar_i( Moment now_mom, int open_bar_i ); - Midi_voice* get_free_midi_voice_l( Moment mom ); -#ifdef MVOICE_LIST - void remove_end_at( Link_list& open_voices_r, Moment mom ); -#else - void remove_end_at( Array& open_voices_r, Moment mom ); -#endif - void output_mudela_begin_bar( Lily_stream& lily_stream_r, Moment now_mom, int bar_i ); - void output_mudela_rest( Lily_stream& lily_stream_r, Moment begin_mom, Moment end_mom ); - void output_mudela_rest_remain( Lily_stream& lily_stream_r, Moment mom ); - -#ifdef TCOL_LIST - Pointer_list tcol_p_list_; -#else - Array tcol_p_array_; -#endif -#ifdef MVOICE_LIST - Pointer_list midi_voice_p_list_; -#else - Array midi_voice_p_array_; -#endif -}; - -#endif // MIDI_TRACK_HH - diff --git a/mi2mu/include/midi-voice.hh b/mi2mu/include/midi-voice.hh deleted file mode 100644 index cc3e023152..0000000000 --- a/mi2mu/include/midi-voice.hh +++ /dev/null @@ -1,32 +0,0 @@ -// -// midi-voice.hh -- declare midi_voice -// -// copyright 1997 Jan Nieuwenhuizen - -#ifndef MIDI_VOICE_HH -#define MIDI_VOICE_HH - -/// (midi_voice) -class Midi_voice { -public: - Midi_voice( Moment begin_mom ); - - void add_event( Midi_event* midi_event_p ); - Moment begin_mom(); - Moment end_mom(); - - String mudela_str( Moment from_mom, Moment to_mom, bool multiple_bo ); - -private: - int events_i_; - Moment end_mom_; - Moment begin_mom_; -#ifdef MEVENT_LIST - Pointer_list midi_event_p_list_; -#else - Array midi_event_p_array_; -#endif -}; - -#endif // MIDI_VOICE_HH - diff --git a/mi2mu/include/track-column.hh b/mi2mu/include/track-column.hh deleted file mode 100644 index 4d5f647a61..0000000000 --- a/mi2mu/include/track-column.hh +++ /dev/null @@ -1,27 +0,0 @@ -// -// track-column.hh -- declare Track_column -// -// copyright 1997 Jan Nieuwenhuizen - -#ifndef TRACK_COLUMN_HH -#define TRACK_COLUMN_HH - -/// (tcol) -class Track_column { -public: - Track_column( Moment mom ); - - void add_event( Midi_event* midi_event_p ); - Moment mom(); - -//private: -#ifdef MEVENT_LIST - Pointer_list midi_event_p_list_; -#else - Array midi_event_p_array_; -#endif - Moment mom_; -}; - -#endif // TRACK_COLUMN_HH - diff --git a/mi2mu/lily-stream.cc b/mi2mu/lily-stream.cc deleted file mode 100644 index 91824e2098..0000000000 --- a/mi2mu/lily-stream.cc +++ /dev/null @@ -1,143 +0,0 @@ -// -// lily-stream.cc -// -// source file of the LilyPond music typesetter -// -// (c) 1997 Jan Nieuwenhuizen - -// should i be named Mudela_stream? - -#include "mi2mu.hh" - -Lily_stream::Lily_stream( String filename_str ) -{ - filename_str_ = filename_str; - os_p_ = 0; - indent_i_ = 0; - comment_mode_b_ = false; - column_i_ = 0; - wrap_column_i_ = 60; - open(); - header(); -} - -Lily_stream::~Lily_stream() -{ - delete os_p_; - if ( indent_i_ ) - warning( "lily indent level: " + String( indent_i_ )); -} - -Lily_stream& -Lily_stream::operator <<( String str ) -{ - static String word_sep_str = "{} \t\n"; - while ( str.length_i() ) { - int i = str.index_any_i( word_sep_str ) + 1; - if ( !i ) - i = str.length_i(); - String word = str.left_str( i ); - str = str.mid_str( i, str.length_i() ); - output_wrapped( word ); - } - return *this; -} - -Lily_stream& -Lily_stream::operator <<( Midi_event& midi_event_r ) -{ - midi_event_r.output_mudela( *this, false ); - *os_p_ << flush; - return *this; -} - -void -Lily_stream::header() -{ - *os_p_ << "% Creator: " << mi2mu_version_str() << "\n"; - *os_p_ << "% Automatically generated, at "; - time_t t( time( 0 ) ); - *os_p_ << ctime( &t ); - *os_p_ << "% from input file: "; - *os_p_ << midi_parser_l_g->filename_str_; - *os_p_ << "\n\n"; - // ugh - *os_p_ << "\\version \"0.1.0\";\n"; -} - -void -Lily_stream::open() -{ - os_p_ = new ofstream( filename_str_ ); - if ( !*os_p_ ) - error ( "can't open `" + filename_str_ + "\'"); -} - -void -Lily_stream::output( String str ) -{ - for ( int i = 0; i < str.length_i(); i++ ) { - char c = str[ i ]; - switch ( c ) { - case '{' : - case '<' : - indent_i_++; - column_i_++; - *os_p_ << c; - break; - case '}' : - case '>' : - assert( indent_i_ ); - indent_i_--; - column_i_++; - *os_p_ << c; - break; - case '%' : - comment_mode_b_ = true; - *os_p_ << c; - column_i_++; - break; - case '\t' : - column_i_ += 8; - *os_p_ << c; - break; - case '\n' : - *os_p_ << endl; - *os_p_ << String( '\t', indent_i_ ); - column_i_ = indent_i_ * 8; - comment_mode_b_ = false; - break; - default : - column_i_++; - *os_p_ << c; - break; - } - } -} - -void -Lily_stream::output_wrapped( String str ) -{ - // enough room left -> doit - if ( column_i_ + str.length_i() <= wrap_column_i_ ) { - output( str ); - return; - } - - // we're at BOL already; this will never fit -> doit - if ( column_i_ == indent_i_ * 8 ) { - output( str ); - return; - } - - // ok, let's wrap - // preserve comment mode - if ( comment_mode_b_ ) - output( String( "\n%" ) ); - else - output( String( "\n" ) ); - - output( str ); -} - - diff --git a/mi2mu/midi-event.cc b/mi2mu/midi-event.cc deleted file mode 100644 index 712a5ae941..0000000000 --- a/mi2mu/midi-event.cc +++ /dev/null @@ -1,227 +0,0 @@ -// -// midi-event.cc -- implement Midi_event -// -// copyright 1997 Jan Nieuwenhuizen - -#include "mi2mu.hh" - -Midi_event::Midi_event() -{ -} - -Moment -Midi_event::mom() -{ - return Moment( 0 ); -} - -void -Midi_event::output_mudela( Lily_stream& lily_stream_r, bool command_mode_bo ) -{ - lily_stream_r << mudela_str( command_mode_bo ) << String( " " ); -} - -Midi_key::Midi_key( int accidentals_i, int minor_i ) -{ - accidentals_i_ = accidentals_i; - minor_i_ = minor_i; - if ( accidentals_i >= 0 ) - key_i_ = ( ( accidentals_i % 7 )[ "cgdaebf" ] - 'a' - 2 ) % 7; - else - key_i_ = ( ( -accidentals_i % 7 )[ "cfbeadg" ] - 'a' - 2 ) % 7; -} - -String -Midi_key::mudela_str( bool command_mode_bo ) -{ - String str = "\\key"; - if ( !minor_i_ ) - str += String( (char)( ( key_i_ + 2 ) % 7 + 'A' ) ); - else // heu, -2: should be - 1 1/2: A -> fis - str += String( (char)( ( key_i_ + 2 - 2 ) % 7 + 'a' ) ); - str = String( "% \"" ) + str - + String('"') + "; % not supported yet\n"; - return str; -} - -String -Midi_key::notename_str( int pitch_i ) -{ - // this may seem very smart, - // but it-s only an excuse not to read a notename table - - // major scale: do-do - // minor scale: la-la ( = + 5 ) - static int notename_i_a[ 12 ] = { 0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6 }; - int notename_i = notename_i_a[ ( minor_i_ * 5 + pitch_i ) % 12 ]; - - static int accidentals_i_a[ 12 ] = { 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 }; - int accidental_i = accidentals_i_a[ minor_i_ * 5 + pitch_i % 12 ]; - if ( accidental_i && ( accidentals_i_ < 0 ) ) { - accidental_i = - accidental_i; - notename_i = ( notename_i + 1 ) % 7; - } - - String notename_str = (char)( ( ( notename_i + 2 ) % 7 ) + 'a' ); - while ( accidental_i-- > 0 ) - notename_str += "is"; - accidental_i++; - while ( accidental_i++ < 0 ) - if ( ( notename_str == "a" ) || ( notename_str == "e" ) ) - notename_str += "s"; - else - notename_str += "es"; - accidental_i--; - - String de_octavate_str = String( '\'', ( Midi_note::c0_pitch_i_c_ + 11 - pitch_i ) / 12 ); - String octavate_str = String( '\'', ( pitch_i - Midi_note::c0_pitch_i_c_ ) / 12 ); - return de_octavate_str + notename_str + octavate_str; -} - -// statics Midi_note -/* - this switch can be used to write simple plets like - c4*2/3 - as - \plet 2/3; c4 \plet 1/1; - */ -bool const Midi_note::simple_plet_b_s = true; - -Midi_note::Midi_note( String name_str, Duration dur ) -{ - // do i want pitch too? - dur_ = dur; - name_str_ = name_str; -} - -String -Midi_note::mudela_str( bool command_mode_bo ) -{ -// assert( !command_mode_bo ); - if ( !dur_.type_i_ ) - return ""; - - if ( simple_plet_b_s ) - return name_str_ + Duration_convert::dur2_str( dur_ ); - - //ugh - String str; - if ( dur_.plet_b() ) - str += String( "\\plet " ) - + String_convert::i2dec_str( dur_.plet_.iso_i_, 0, 0 ) - + "/" - + String_convert::i2dec_str( dur_.plet_.type_i_, 0, 0 ) - + "; "; - - str += name_str_; - - Duration dur = dur_; - dur.set_plet( 1,1 ); - str += Duration_convert::dur2_str( dur ); - - if ( dur_.plet_b() ) - str += String( " \\plet 1/1;" ); - - return str; -} - -Moment -Midi_note::mom() -{ - return Duration_convert::dur2_mom( dur_ ); -} - -Midi_tempo::Midi_tempo( int useconds_per_4_i ) -{ - useconds_per_4_i_ = useconds_per_4_i; - seconds_per_1_f_ = (Real)useconds_per_4_i_ * 4 / 1e6; -} - -String -Midi_tempo::mudela_str( bool command_mode_bo ) -{ -// assert( command_mode_bo ); - if ( !command_mode_bo ) - return ""; - String str = "\\tempo 4:"; - str += String( get_tempo_i( Moment( 1, 4 ) ) ); - str += ";"; - return str; -} - -int -Midi_tempo::useconds_per_4_i() -{ - return useconds_per_4_i_; -} - -int -Midi_tempo::get_tempo_i( Moment moment ) -{ - return Moment( 60 ) / moment / Moment( seconds_per_1_f_ ); -} - -Midi_text::Midi_text( Midi_text::Type type, String text_str ) -{ - type_ = type; - text_str_ = text_str; -} - -String -Midi_text::mudela_str( bool command_mode_bo ) -{ - (void)command_mode_bo; - if ( !text_str_.length_i() - || ( text_str_.length_i() != (int)strlen( text_str_.ch_C() ) ) ) - return ""; - - return "% " + text_str_ + "\n"; -} - -Midi_time::Midi_time( int num_i, int den_i, int clocks_4_i, int count_32_i ) -{ - sync_dur_.type_i_ = 8; - - sync_f_ = 1.0; - if ( count_32_i != 8 ) - warning( String( "#32 in quarter: " ) + String( count_32_i )); - num_i_ = num_i; - den_i_ = den_i; - clocks_1_i_ = clocks_4_i * 4; -} - -Moment -Midi_time::bar_mom() -{ - Duration d; - d.type_i_ = 1 << den_i_ ; - return Moment( num_i_ ) * Duration_convert::dur2_mom( d ); -} - -int -Midi_time::clocks_1_i() -{ - return clocks_1_i_; -} - -int -Midi_time::den_i() -{ - return den_i_; -} - -int -Midi_time::num_i() -{ - return num_i_; -} - -String -Midi_time::mudela_str( bool command_mode_bo ) -{ - String str = "\\meter " - + String( num_i_ ) + "/" + String( 1 << den_i_ ) - + ";"; - return str; -} - diff --git a/mi2mu/midi-score.cc b/mi2mu/midi-score.cc deleted file mode 100644 index 7b3262045c..0000000000 --- a/mi2mu/midi-score.cc +++ /dev/null @@ -1,79 +0,0 @@ -// -// midi-score.cc -- implement Midi_score -// -// copyright 1997 Jan Nieuwenhuizen - -#include "mi2mu.hh" - -Midi_score::Midi_score( int format_i, int tracks_i, int tempo_i ) -{ - format_i_ = format_i; - tracks_i_ = tracks_i; - tempo_i_ = tempo_i; -} - -Midi_score::~Midi_score() -{ -} - -void -Midi_score::add_track( Midi_track* midi_track_p ) -{ - midi_track_p_list_.bottom().add( midi_track_p ); -} - -int -Midi_score::output_mudela( String filename_str ) -{ - tor( NORMAL_ver ) << "Lily output to " << filename_str << " ..." << endl; - - // ugh, ugly midi type 1 fix - if ( ( midi_track_p_list_.size() == 1 ) && !midi_track_p_list_.top()->number_i_ ) - midi_track_p_list_.top()->number_i_ = 1; - - int track_i = 0; - Lily_stream lily_stream( filename_str ); - for ( PCursor i( midi_track_p_list_.top() ); i.ok(); i++ ) { - tor( NORMAL_ver ) << "track " << track_i++ << ": " << flush; - i->output_mudela( lily_stream ); - lily_stream << "\n"; - tor( NORMAL_ver ) << endl; - } - - lily_stream << "\\score{\n"; - lily_stream << " < \\multi 3;\n"; - for ( PCursor i( midi_track_p_list_.top() ); i.ok(); i++ ) { - if ( ( midi_track_p_list_.size() != 1 ) - && ( i == midi_track_p_list_.top() ) ) - continue; - lily_stream << "\\melodic{ "; - lily_stream << "\\$" << i->id_str(); - lily_stream << " }\n"; - } - lily_stream << ">\n"; - - lily_stream << "\\paper{"; - lily_stream << "unitspace = 20.0\\mm;"; - lily_stream << "}\n"; - - lily_stream << "\\midi{"; - // not use silly 0 track - midi_track_p_list_.bottom()->midi_tempo_p_->output_mudela( lily_stream, true ); - lily_stream << "}\n"; - - lily_stream << "}\n"; - - return 0; -} - -void -Midi_score::process() -{ - int track_i = 0; - for ( PCursor i( midi_track_p_list_.top() ); i.ok(); i++ ) { - tor( NORMAL_ver ) << "track " << track_i++ << ": " << flush; - i->process(); - tor( NORMAL_ver ) << endl; - } -} - diff --git a/mi2mu/midi-track.cc b/mi2mu/midi-track.cc deleted file mode 100644 index 0efb703501..0000000000 --- a/mi2mu/midi-track.cc +++ /dev/null @@ -1,536 +0,0 @@ -// -// midi-track.cc -- implement Midi_track -// -// copyright 1997 Jan Nieuwenhuizen - -#include "mi2mu.hh" - -Midi_track::Midi_track( int number_i, String copyright_str, String track_name_str, String instrument_str ) -{ - number_i_ = number_i; - copyright_str_ = copyright_str; - instrument_str_ = instrument_str; - name_str_ = track_name_str; - midi_time_p_ = new Midi_time( 4, 2, 24, 8 ); - midi_tempo_p_ = new Midi_tempo( 1000000 ); -#ifdef TCOL_LIST - tcol_p_list_.bottom().add( new Track_column( Moment( 0 ) ) ); -#else - tcol_p_array_.push( new Track_column( Moment( 0 ) ) ); -#endif -} - -Midi_track::~Midi_track() -{ - delete midi_time_p_; - delete midi_tempo_p_; -} - -#ifdef MVOICE_LIST -void -Midi_track::add_begin_at( Link_list& open_voices_r, Moment mom ) -{ - for ( PCursor i( midi_voice_p_list_.top() ); i.ok(); i++ ) - if ( i->begin_mom() == mom ) { - tor( DEBUG_ver ) << "open_voices (" << open_voices_r.size() << "): +1\n"; - open_voices_r.bottom().add( *i ); - } -} -#else -void -Midi_track::add_begin_at( Array& open_voices_r, Moment mom ) -{ - for ( int i = 0; i < midi_voice_p_array_.size(); i++ ) - if ( midi_voice_p_array_[ i ]->begin_mom() == mom ) { - tor( DEBUG_ver ) << "open_voices (" << open_voices_r.size() << "): +1\n"; - open_voices_r.push( midi_voice_p_array_[ i ] ); - } -} -#endif - -void -Midi_track::add_event( Moment mom, Midi_event* midi_event_p ) -{ - if ( ! midi_event_p ) - return; - tcol_l( mom - midi_event_p->mom() )->add_event( midi_event_p ); -} - -int -Midi_track::check_begin_bar_i( Moment now_mom, int open_bar_i ) -{ - Moment bar_mom = midi_time_p_->bar_mom(); - int bar_i = (int)( now_mom / bar_mom ) + 1; - if ( bar_i > open_bar_i ) { - tor( NORMAL_ver ) << '[' << flush; - return bar_i; - } - return 0; -} - -int -Midi_track::check_end_bar_i( Moment now_mom, int open_bar_i ) -{ - Moment bar_mom = midi_time_p_->bar_mom(); - int bar_i = (int)( now_mom / bar_mom ) + 1; - if ( bar_i > open_bar_i ) { - tor( NORMAL_ver ) << ']' << flush; - return bar_i; - } - return open_bar_i; -} - -Moment -Midi_track::end_mom() -{ - // heu.. - Moment mom = 0.0; -#ifdef MVOICE_LIST - for ( PCursor i( midi_voice_p_list_.top() ); i.ok(); i++ ) - mom = i->end_mom() >? mom; -#else - for ( int i = 0; i < midi_voice_p_array_.size(); i++ ) - mom = midi_voice_p_array_[ i ]->end_mom() >? mom; -#endif - return mom; -} - -Midi_voice* -Midi_track::get_free_midi_voice_l( Moment mom ) -{ -#ifdef MVOICE_LIST - Real f = mom; - for ( PCursor i( midi_voice_p_list_.top() ); i.ok(); i++ ) { - Real e = i->end_mom(); - if ( i->end_mom() == mom ) - return *i; - } - - Midi_voice* midi_voice_p = new Midi_voice( mom ); - Midi_voice* midi_voice_l = midi_voice_p; - midi_voice_p_list_.bottom().add( midi_voice_p ); - return midi_voice_l; -#else - Real f = mom; - for ( int i = 0; i < midi_voice_p_array_.size(); i++ ) { - Real e = i->end_mom(); - if ( midi_voice_p_array_[ i ]->end_mom() == mom ) - return midi_voice_p_array_[ i ]; - } - - Midi_voice* midi_voice_p = new Midi_voice( mom ); - Midi_voice* midi_voice_l = midi_voice_p; - midi_voice_p_array_.push( midi_voice_p ); - return midi_voice_l; -#endif -} - -String -Midi_track::id_str() -{ - String str = name_str(); - for ( int i = 0; i < str.length_i(); i++ ) - if ( ( !i && !isalpha( str[ i ] ) ) - || !isalnum( str[ i ] ) ) - *( str.ch_l() + i ) = '_'; - return str; -} - -String -Midi_track::name_str() -{ - if ( name_str_.length_i() ) - return name_str_; - return String( "track" ) + String( number_i_ ); -} - -Moment -Midi_track::next_begin_mom( Moment now_mom ) -{ -// Moment begin_mom = Midi_track::end_mom() + 1; - Moment begin_mom = Midi_track::end_mom(); -#ifdef MVOICE_LIST - for ( PCursor i( midi_voice_p_list_.top() ); i.ok(); i++ ) - if ( i->begin_mom() > now_mom ) - begin_mom = begin_mom begin_mom(); -#else - for ( int i = 0; i < midi_voice_p_array_.size(); i++ ) - if ( midi_voice_p_array_[ i ]->begin_mom() > now_mom ) - begin_mom = begin_mom begin_mom(); -#endif - return begin_mom; -} - -Moment -Midi_track::next_end_mom( Moment now_mom ) -{ - Moment end_mom = Midi_track::end_mom(); -#ifdef MVOICE_LIST - for ( PCursor i( midi_voice_p_list_.top() ); i.ok(); i++ ) - if ( i->end_mom() > now_mom ) - end_mom = end_mom end_mom(); -#else - for ( int i = 0; i < midi_voice_p_array_.size(); i++ ) - if ( midi_voice_p_array_[ i ]->end_mom() > now_mom ) - end_mom = end_mom end_mom(); -#endif - return end_mom; -} - -void -Midi_track::process() -{ - /* - columns to voices - */ -// int bar_i = 1; - int bar_i = 0; -#ifdef TCOL_LIST - for ( PCursor i( tcol_p_list_.top() ); i.ok(); i++ ) { - int begin_bar_i = check_begin_bar_i( i->mom(), bar_i ); - if ( begin_bar_i ) - tor( NORMAL_ver ) << begin_bar_i << flush; - while ( i->midi_event_p_list_.size() ) - get_free_midi_voice_l( i->mom() )->add_event( i->midi_event_p_list_.top().remove_p() ); - bar_i = check_end_bar_i( i->mom(), bar_i ); - } -#else - for ( int i = 0; i < tcol_p_array_.size(); i++ ) { - Track_column* tcol_l = tcol_p_array_[ i ]; - int begin_bar_i = check_begin_bar_i( tcol_l->mom(), bar_i ); - if ( begin_bar_i ) - tor( NORMAL_ver ) << begin_bar_i << flush; -#ifdef MEVENT_LIST - while ( tcol_l->midi_event_p_list_.size() ) - get_free_midi_voice_l( tcol_l->mom() )->add_event( tcol_l->midi_event_p_list_.top().remove_p() ); -#else - // what's efficient here? -#if 0 // heu, what's different here? - while ( tcol_l->midi_event_p_array_.size() ) { - get_free_midi_voice_l( tcol_l->mom() )->add_event( tcol_l->midi_event_p_array_[ 0 ] ); - tcol_l->midi_event_p_array_.del( 0 ); - } -#else - for ( int j = 0; j < tcol_l->midi_event_p_array_.size(); j++ ) { - get_free_midi_voice_l( tcol_l->mom() )->add_event( tcol_l->midi_event_p_array_[ j ] ); - tcol_l->midi_event_p_array_[ j ] = 0; - } - tcol_l->midi_event_p_array_.clear(); -#endif -#endif - bar_i = check_end_bar_i( tcol_l->mom(), bar_i ); - } -#endif - - tor( DEBUG_ver ) << "ends: " << endl; - int n = 0; -#ifdef MVOICE_LIST - for ( PCursor i( midi_voice_p_list_.top() ); i.ok(); i++ ) - tor( VERBOSE_ver ) << "voice " << n++ << ": " << i->end_mom() << endl; -#else - for ( int i = 0; i < midi_voice_p_array_.size(); i++ ) - tor( VERBOSE_ver ) << "voice " << n++ << ": " << midi_voice_p_array_[ i ]->end_mom() << endl; -#endif - tor( DEBUG_ver ) << ":sdne" << endl; -} - -void -Midi_track::output_mudela( Lily_stream& lily_stream_r ) -{ - lily_stream_r << "$" << id_str() << " = \\melodic{\n"; - lily_stream_r << "% midi copyright:" << copyright_str_ << "\n"; - lily_stream_r << "% instrument:" << instrument_str_ << "\n"; -// int bar_i = 1; - int bar_i = 0; - -#ifdef MVOICE_LIST - Link_list open_voices; -#else - Array open_voices; -#endif - Moment now_mom = 0.0; - Real now_f = now_mom; - Real begin_f = 0; - Real end_f = end_mom(); - Real then_f; - - /* - now we step through time while writing all voices - - we can only output time slices that have a constant - number of open voices; each begin or end of a voice - starts or ends a chord or multivoice - - [todo] - voice defragmentation/concatenation could make this - lost blonder - */ - - bool start_of_track_bo = true; - - /// ugh, avoid status track 0 full of rests... - while ( number_i_ && ( now_mom < end_mom() ) ) { - int begin_bar_i = check_begin_bar_i( now_mom, bar_i ); - if ( begin_bar_i ) - output_mudela_begin_bar( lily_stream_r, now_mom, begin_bar_i ); - add_begin_at( open_voices, now_mom ); - - Moment begin_mom = next_begin_mom( now_mom ); - - if ( begin_bar_i ) - tor( NORMAL_ver ) << begin_bar_i << flush; - - Moment end_mom = next_end_mom( now_mom ); - Moment then_mom = 0.0; - if ( ( begin_mom > now_mom ) && ( begin_mom < end_mom ) ) - then_mom = begin_mom; - else - then_mom = end_mom; - - tor( DEBUG_ver ) << "begin: " << begin_mom << " end: " << end_mom << endl; - tor( DEBUG_ver ) << "slice: " << now_mom << ", " << then_mom << endl; - - now_f = now_mom; - begin_f = begin_mom; - end_f = end_mom; - then_f = then_mom; - -// ugh, rests -// checking for no open voice does not work for initial rests. -// for some reason the voice is open, but does not procuce notes? - if ( open_voices.size() > 1 ) - lily_stream_r << "< "; - if ( start_of_track_bo ) { - start_of_track_bo = false; - String str; -#ifdef MVOICE_LIST - for ( PCursor i( open_voices.top() ); i.ok(); i++ ) - lily_stream_r << i->mudela_str( now_mom, then_mom, open_voices.size() - 1 ); -#else - for ( int i = 0; i < open_voices.size(); i++ ) - lily_stream_r << open_voices[ i ]->mudela_str( now_mom, then_mom, open_voices.size() - 1 ); -#endif - if ( str.length_i() ) - lily_stream_r << str; - else - output_mudela_rest( lily_stream_r, now_mom, then_mom ); - } - else { -#ifdef MVOICE_LIST - for ( PCursor i( open_voices.top() ); i.ok(); i++ ) - lily_stream_r << i->mudela_str( now_mom, then_mom, open_voices.size() - 1 ); -#else - for ( int i = 0; i < open_voices.size(); i++ ) - lily_stream_r << open_voices[ i ]->mudela_str( now_mom, then_mom, open_voices.size() - 1 ); -#endif - if ( !open_voices.size() ) - output_mudela_rest( lily_stream_r, now_mom, then_mom ); - } -// *lily_stream_r.os_p_ << flush; - - if ( open_voices.size() > 1 ) - lily_stream_r << "> "; - remove_end_at( open_voices, then_mom ); - - bar_i = check_end_bar_i( now_mom, bar_i ); - - now_mom = then_mom; - } -// bar_i++; -// tor( NORMAL_ver ) << '[' << bar_i << ']' << flush; - - lily_stream_r << "} % " << name_str() << "\n"; -} - - -void -Midi_track::output_mudela_begin_bar( Lily_stream& lily_stream_r, Moment now_mom, int bar_i ) -{ - Moment bar_mom = midi_time_p_->bar_mom(); - Moment into_bar_mom = now_mom - Moment( bar_i - 1 ) * bar_mom; - if ( bar_i > 1 ) { - if ( !into_bar_mom ) - lily_stream_r << "|\n"; - } - lily_stream_r << "% " << String_convert::i2dec_str( bar_i, 0, ' ' ); - if ( into_bar_mom ) - lily_stream_r << ":" << Duration_convert::dur2_str( Duration_convert::mom2_dur( into_bar_mom ) ); - lily_stream_r << "\n"; -} - - -void -Midi_track::output_mudela_rest( Lily_stream& lily_stream_r, Moment begin_mom, Moment end_mom ) -{ - Moment bar_mom = midi_time_p_->bar_mom(); - Moment now_mom = begin_mom; - - int begin_bar_i = (int)( now_mom / bar_mom ) + 1; - int end_bar_i = (int)( end_mom / bar_mom ) + 1; - - if ( end_bar_i == begin_bar_i ) { - output_mudela_rest_remain( lily_stream_r, end_mom - begin_mom ); - return; - } - - // multiple bars involved - int bar_i = (int)( now_mom / bar_mom ) + 1; - - //fill current bar - Moment begin_bar_mom = Moment( begin_bar_i - 1 ) * bar_mom; - if ( now_mom > begin_bar_mom ) { - int next_bar_i = (int)( now_mom / bar_mom ) + 2; - Moment next_bar_mom = Moment( next_bar_i - 1 ) * bar_mom; - assert( next_bar_mom <= end_mom ); - - Moment remain_mom = next_bar_mom - now_mom; - if ( remain_mom > Moment( 0 ) ) { - output_mudela_rest_remain( lily_stream_r, remain_mom ); - now_mom += remain_mom; - } - - bar_i = check_end_bar_i( now_mom, bar_i ); - } - - // fill whole bars - int count_i = end_bar_i - bar_i; - for ( int i = 0; i < count_i; i++ ) { - int begin_bar_i = check_begin_bar_i( now_mom, bar_i ); - if ( begin_bar_i ) - output_mudela_begin_bar( lily_stream_r, now_mom, begin_bar_i ); - lily_stream_r << "r1 "; -// *lily_stream_r.os_p_ << flush; - if ( begin_bar_i ) - tor( NORMAL_ver ) << begin_bar_i << flush; - bar_i = check_end_bar_i( now_mom, bar_i ); - now_mom += bar_mom; - } - - // use "int i" here, and gcc 2.7.2 hits internal compiler error - int ii = check_begin_bar_i( now_mom, bar_i ); - if ( ii ) - output_mudela_begin_bar( lily_stream_r, now_mom, ii ); - -// bar_i = check_end_bar_i( now_mom, bar_i ); - - Moment remain_mom = end_mom - Moment( end_bar_i - 1 ) * bar_mom; - if ( remain_mom > Moment( 0 ) ) { - output_mudela_rest_remain( lily_stream_r, remain_mom ); - now_mom += remain_mom; - } - assert( now_mom == end_mom ); -} - -void -Midi_track::output_mudela_rest_remain( Lily_stream& lily_stream_r, Moment mom ) -{ - if ( Duration_convert::no_quantify_b_s ) { - Duration dur = Duration_convert::mom2_dur( mom ); - lily_stream_r << "r" << dur.str() << " "; -// assert( mom == dur.mom() ); - assert( mom == dur.length() ); - return; - } - - Duration dur = Duration_convert::mom2standardised_dur( mom ); - if ( dur.type_i_ ) - lily_stream_r << "r" << dur.str() << " "; -} - - -#ifdef MVOICE_LIST -void -Midi_track::remove_end_at( Link_list& open_voices_r, Moment mom ) -{ - for ( PCursor i( open_voices_r.top() ); i.ok(); i++ ) - if ( i->end_mom() <= mom ) { - tor( DEBUG_ver ) << "open_voices (" << open_voices_r.size() << "): -1\n"; - i.remove_p(); - if ( !i.ok() ) - break; - } -} -#else -void -Midi_track::remove_end_at( Array& open_voices_r, Moment mom ) -{ - for ( int i = 0; i < open_voices_r.size(); i++ ) - if ( midi_voice_p_array_[ i ]->end_mom() <= mom ) { - tor( DEBUG_ver ) << "open_voices (" << open_voices_r.size() << "): -1\n"; - open_voices_r[ i ] = 0; -// open_voices_r.del( i-- ); - open_voices_r.del( i ); - } -} -#endif - -void -Midi_track::set_tempo( int useconds_per_4_i ) -{ - delete midi_tempo_p_; - midi_tempo_p_ = new Midi_tempo( useconds_per_4_i ); -} - -void -Midi_track::set_time( int num_i, int den_i, int clocks_i, int count_32_i ) -{ - delete midi_time_p_; - midi_time_p_ = new Midi_time( num_i, den_i, clocks_i, count_32_i ); -} - -Track_column* -Midi_track::tcol_l( Moment mom ) -{ -#ifdef TCOL_LIST - for ( PCursor i( tcol_p_list_.top() ); i.ok(); i++ ) { - if ( i->mom() > mom ) { //not used, let's use array! -// assert( 0 ); -// 97-07-21; it's used now! cannot use array - Track_column* tcol_p = new Track_column( mom ); - i.insert( tcol_p ); - return tcol_p; - } - if ( i->mom() == mom ) - return *i; - } - - Track_column* tcol_p = new Track_column( mom ); - tcol_p_list_.bottom().add( tcol_p ); - return tcol_p; -#elif 0 - for ( int i = 0; i < tcol_p_array_.size(); i++ ) - if ( tcol_p_array_[ i ]->mom() == mom ) - return tcol_p_array_[ i ]; - - Track_column* tcol_p = new Track_column( mom ); - tcol_p_array_.push( tcol_p ); - return tcol_p; -#else - /* - as "insert" is never called, the right column will - always be found, unless mom > tcol_p_array[ i ]->mom(). - */ - int upper_i = max( 0, tcol_p_array_.size() - 1 ); - int lower_i = 0; - int i = upper_i; - while ( 1 ) { - Moment i_mom = tcol_p_array_[ i ]->mom(); - if ( i_mom == mom ) - return tcol_p_array_[ i ]; - if ( mom < i_mom ) - upper_i = i; - else - lower_i = i; - if ( ( upper_i == lower_i ) || ( i == tcol_p_array_.size() - 1 ) ) { -// huh? assert ( upper_i == tcol_p_array_.size() ); - Track_column* tcol_p = new Track_column( mom ); - tcol_p_array_.push( tcol_p ); - return tcol_p; - } - i = ( upper_i + lower_i + 1 ) / 2; - } - assert( 0 ); - return 0; -#endif -} - diff --git a/mi2mu/midi-voice.cc b/mi2mu/midi-voice.cc deleted file mode 100644 index 77a6526ef8..0000000000 --- a/mi2mu/midi-voice.cc +++ /dev/null @@ -1,102 +0,0 @@ -// -// midi-voice.cc -- implement midi_voice -// -// copyright 1997 Jan Nieuwenhuizen - -#include "mi2mu.hh" - -Midi_voice::Midi_voice( Moment begin_mom ) -{ - begin_mom_ = begin_mom; - end_mom_ = begin_mom; - events_i_ = 0; -} - -void -Midi_voice::add_event( Midi_event* midi_event_p ) -{ -#ifdef MEVENT_LIST - midi_event_p_list_.bottom().add( midi_event_p ); -#else - midi_event_p_array_.push( midi_event_p ); -#endif -} - -Moment -Midi_voice::begin_mom() -{ - return begin_mom_; -} - -Moment -Midi_voice::end_mom() -{ -#ifdef MEVENT_LIST -// if ( events_i_ == midi_event_p_list_.length_i() ) - if ( events_i_ == midi_event_p_list_.size() ) - return end_mom_; - Moment now_mom = begin_mom_; - tor( DEBUG_ver ) << now_mom << ", "; - for ( PCursor i( midi_event_p_list_.top() ); i.ok(); i++ ) { - tor( DEBUG_ver ) << now_mom << ", "; - now_mom += i->mom(); - } - tor( DEBUG_ver ) << endl; - end_mom_ = now_mom; -// events_i_ = midi_event_p_list_.length_i(); - events_i_ = midi_event_p_list_.size(); - return end_mom_; -#else - if ( events_i_ == midi_event_p_array_.size() ) - return end_mom_; - Moment now_mom = begin_mom_; - tor( DEBUG_ver ) << now_mom << ", "; - for ( int i = 0; i < midi_event_p_array_.size(); i++ ) { - tor( DEBUG_ver ) << now_mom << ", "; - now_mom += midi_event_p_array_[ i ]->mom(); - } - tor( DEBUG_ver ) << endl; - end_mom_ = now_mom; - events_i_ = midi_event_p_array_.size(); - return end_mom_; -#endif -} - -String -Midi_voice::mudela_str( Moment from_mom, Moment to_mom, bool multiple_bo ) -{ - String str; - -// if ( begin_mom() >= to_mom ) - if ( begin_mom() > to_mom ) - return ""; -// if ( end_mom() <= from_mom ) - if ( end_mom() < from_mom ) - return ""; - - Moment now_mom = begin_mom(); -#ifdef MEVENT_LIST - PCursor i( midi_event_p_list_.top() ); - for ( ; i.ok() && now_mom < from_mom ; i++ ) - now_mom += i->mom(); - - for ( ; i.ok() && now_mom < to_mom ; i++ ) { - now_mom += i->mom(); - str += i->mudela_str( false ) + " "; - } -#else - int i = 0; - for ( ; i < midi_event_p_array_.size() && now_mom < from_mom ; i++ ) - now_mom += midi_event_p_array_[ i ]->mom(); - - for ( ; i < midi_event_p_array_.size() && now_mom < to_mom ; i++ ) { - now_mom += midi_event_p_array_[ i ]->mom(); - str += midi_event_p_array_[ i ]->mudela_str( false ) + " "; - } -#endif - - if ( str.length_i() && multiple_bo ) - str = "{ " + str + "} "; - return str; -} - diff --git a/mi2mu/track-column.cc b/mi2mu/track-column.cc deleted file mode 100644 index a7faedf168..0000000000 --- a/mi2mu/track-column.cc +++ /dev/null @@ -1,27 +0,0 @@ -// -// track-column.cc -- implement Track_column -// -// copyright 1997 Jan Nieuwenhuizen - -#include "mi2mu.hh" - -Track_column::Track_column( Moment mom ) -{ - mom_ = mom; -} - -void -Track_column::add_event( Midi_event* midi_event_p ) -{ -#ifdef MEVENT_LIST - midi_event_p_list_.bottom().add( midi_event_p ); -#else - midi_event_p_array_.push( midi_event_p ); -#endif -} - -Moment -Track_column::mom() -{ - return mom_; -}