From: fred Date: Sun, 24 Mar 2002 19:51:06 +0000 (+0000) Subject: lilypond-0.1.7 X-Git-Tag: release/1.5.59~4274 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=049a1c3d0862b5676eef8e656426ca4357ca48ef;p=lilypond.git lilypond-0.1.7 --- diff --git a/lib/include/duration.hh b/lib/include/duration.hh index c8554f343a..c46fc5a7c0 100644 --- a/lib/include/duration.hh +++ b/lib/include/duration.hh @@ -18,11 +18,12 @@ // ugh, to get me in lily lib extern bool no_triplets_bo_g; -/** (plet) - The type and replacement value of a plet (triplet, quintuplet.) Conceptually the same as a rational, but 4/6 != 2/3 +/** + The type and replacement value of a plet (triplet, quintuplet.) Conceptually the same as a rational, but 4/6 != 2/3. + + (plet) */ struct Plet { - Plet( int replace_i, int type_i ); Plet(); Moment mom()const; bool unit_b()const; @@ -39,7 +40,7 @@ struct Duration { /** Ctor of Duration. type_i should be a power of 2. */ - Duration( int type_i = 1, int dots_i = 0); + Duration(); /// is the "plet factor" of this note != 1 ? bool plet_b(); String str()const; diff --git a/mi2mu/VERSION b/mi2mu/VERSION index 5596987483..22b9eff149 100644 --- a/mi2mu/VERSION +++ b/mi2mu/VERSION @@ -1,6 +1,6 @@ MAJOR_VERSION = 0 MINOR_VERSION = 0 -PATCH_LEVEL = 18 +PATCH_LEVEL = 19 # use to send patches, always empty for released version: MY_PATCH_LEVEL = # diff --git a/mi2mu/include/lily-stream.hh b/mi2mu/include/lily-stream.hh index 8c6622d324..755d19fb55 100644 --- a/mi2mu/include/lily-stream.hh +++ b/mi2mu/include/lily-stream.hh @@ -9,26 +9,26 @@ #define LILY_STREAM_HH /// Lily output -struct Lily_stream { - ostream* os_p_; - String filename_str_; - int indent_i_; - int column_i_; - int wrap_column_i_; - bool comment_mode_bo_; - +class Lily_stream { +public: Lily_stream( String filename_str ); ~Lily_stream(); Lily_stream& operator <<( String str ); Lily_stream& operator <<( Midi_event& midi_event_r ); - void check_comment( String str ); +private: void header(); - void indent(); - void newline(); void open(); - void tnedni(); + 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/midi-track.hh b/mi2mu/include/midi-track.hh index c25d65831b..3d654ae3df 100644 --- a/mi2mu/include/midi-track.hh +++ b/mi2mu/include/midi-track.hh @@ -14,6 +14,7 @@ public: 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 ); diff --git a/mi2mu/lily-stream.cc b/mi2mu/lily-stream.cc index eeb3c14189..91824e2098 100644 --- a/mi2mu/lily-stream.cc +++ b/mi2mu/lily-stream.cc @@ -14,7 +14,7 @@ Lily_stream::Lily_stream( String filename_str ) filename_str_ = filename_str; os_p_ = 0; indent_i_ = 0; - comment_mode_bo_ = false; + comment_mode_b_ = false; column_i_ = 0; wrap_column_i_ = 60; open(); @@ -31,49 +31,15 @@ Lily_stream::~Lily_stream() Lily_stream& Lily_stream::operator <<( String str ) { - static String nobreak_str = "\\`'_-.^<>*@"; + static String word_sep_str = "{} \t\n"; while ( str.length_i() ) { - int max_i = wrap_column_i_ - column_i_ - 1; - int i = str.length_i() - 1 8 * indent_i_ ) { - newline(); - if ( comment_mode_bo_ && ( str[ 0 ] != '%' ) ) - str = "%" + str; - continue; - } - else { // cannot break neatly... - i = max_i; - } - } - } - - String line = str.left_str( i + 1 ); - str = str.mid_str( i + 1, INT_MAX ); - *os_p_ << line; - column_i_ += line.length_i(); - if ( nl_i != -1 ) - newline(); - else - check_comment( line ); - if ( ( str.length_i() && ( nl_i == -1 ) ) || ( column_i_ >= wrap_column_i_ ) ) { - //brr. - if ( comment_mode_bo_ ) - str = "%" + str; - newline(); - } - } + 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; } @@ -85,18 +51,6 @@ Lily_stream::operator <<( Midi_event& midi_event_r ) return *this; } -void -Lily_stream::check_comment( String str ) -{ - int newline_i = str.index_last_i( '\n' ); - if ( newline_i != -1 ) { - str = str.mid_str( newline_i +1, INT_MAX ); - comment_mode_bo_ = false; - } - if ( str.index_i( '%' ) != -1 ) - comment_mode_bo_ = true; -} - void Lily_stream::header() { @@ -108,24 +62,7 @@ Lily_stream::header() *os_p_ << midi_parser_l_g->filename_str_; *os_p_ << "\n\n"; // ugh - *os_p_ << "\\version \"0.0.61\";\n"; -} -/* - snapnie: dit kan toch automaties? Zie ook dstream. - */ -void -Lily_stream::indent() -{ - indent_i_++; - newline(); -} - -void -Lily_stream::newline() -{ - *os_p_ << endl << String( '\t', indent_i_ ); - column_i_ = indent_i_ * 8; - comment_mode_bo_ = false; + *os_p_ << "\\version \"0.1.0\";\n"; } void @@ -137,10 +74,70 @@ Lily_stream::open() } void -Lily_stream::tnedni() +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 ) { - assert( indent_i_ > 0 ); - indent_i_--; - newline(); + // 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-parser.y b/mi2mu/midi-parser.y index ce33c6bc83..d28e907340 100644 --- a/mi2mu/midi-parser.y +++ b/mi2mu/midi-parser.y @@ -148,8 +148,6 @@ the_meta_event: break; case Midi_text::TRACK_NAME: midi_parser_l_g->track_name_str_ = *$2; - while ( midi_parser_l_g->track_name_str_.index_i( ' ' ) != -1 ) - *(midi_parser_l_g->track_name_str_.ch_l() + midi_parser_l_g->track_name_str_.index_i( ' ' ) ) = '_'; break; case Midi_text::INSTRUMENT_NAME: midi_parser_l_g->instrument_str_ = *$2; diff --git a/mi2mu/midi-score.cc b/mi2mu/midi-score.cc index 62cc98910f..7b3262045c 100644 --- a/mi2mu/midi-score.cc +++ b/mi2mu/midi-score.cc @@ -36,42 +36,32 @@ Midi_score::output_mudela( String 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.newline(); + lily_stream << "\n"; tor( NORMAL_ver ) << endl; } - lily_stream << "\\score{"; - lily_stream.indent(); - lily_stream << " < \\multi 3;"; - lily_stream.indent(); - 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->name_str(); - lily_stream << " }"; - lily_stream.newline(); - } - lily_stream.tnedni(); - lily_stream << ">"; - lily_stream.newline(); - lily_stream << "\\paper{"; - lily_stream.indent(); - lily_stream << "unitspace = 20.0\\mm;"; - lily_stream.tnedni(); - lily_stream << "}"; - lily_stream.newline(); - lily_stream << "\\midi{"; - lily_stream.indent(); - // not use silly 0 track - midi_track_p_list_.bottom()->midi_tempo_p_->output_mudela( lily_stream, true ); - lily_stream.tnedni(); - lily_stream << "}"; - lily_stream.tnedni(); + 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 << "}"; - lily_stream.newline(); + lily_stream << "}\n"; return 0; } diff --git a/mi2mu/midi-track.cc b/mi2mu/midi-track.cc index f575ccfe68..0efb703501 100644 --- a/mi2mu/midi-track.cc +++ b/mi2mu/midi-track.cc @@ -125,6 +125,17 @@ Midi_track::get_free_midi_voice_l( Moment mom ) #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() { @@ -223,17 +234,12 @@ Midi_track::process() tor( DEBUG_ver ) << ":sdne" << endl; } - void Midi_track::output_mudela( Lily_stream& lily_stream_r ) { - lily_stream_r << name_str() << " = \\melodic{"; - lily_stream_r.indent(); - lily_stream_r << "% midi copyright:" << copyright_str_; - lily_stream_r.newline(); - lily_stream_r << "% instrument:" << instrument_str_; - lily_stream_r.newline(); - + 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; @@ -333,9 +339,7 @@ Midi_track::output_mudela( Lily_stream& lily_stream_r ) // bar_i++; // tor( NORMAL_ver ) << '[' << bar_i << ']' << flush; - lily_stream_r.tnedni(); - lily_stream_r << "} % " << name_str(); - lily_stream_r.newline(); + lily_stream_r << "} % " << name_str() << "\n"; } @@ -346,13 +350,12 @@ Midi_track::output_mudela_begin_bar( Lily_stream& lily_stream_r, Moment now_mom, Moment into_bar_mom = now_mom - Moment( bar_i - 1 ) * bar_mom; if ( bar_i > 1 ) { if ( !into_bar_mom ) - lily_stream_r << "|"; - lily_stream_r.newline(); + 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.newline(); + lily_stream_r << "\n"; }