]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.1.7
authorfred <fred>
Sun, 24 Mar 2002 19:51:06 +0000 (19:51 +0000)
committerfred <fred>
Sun, 24 Mar 2002 19:51:06 +0000 (19:51 +0000)
lib/include/duration.hh
mi2mu/VERSION
mi2mu/include/lily-stream.hh
mi2mu/include/midi-track.hh
mi2mu/lily-stream.cc
mi2mu/midi-parser.y
mi2mu/midi-score.cc
mi2mu/midi-track.cc

index c8554f343a3b0620fb42b4359c6833a47fde765d..c46fc5a7c0d7320ad4ef9834ec46e421e970e6fa 100644 (file)
 // 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;
index 5596987483e885411df781e0b6cbb62f1255d9ef..22b9eff149db9de3da073571260d946582181667 100644 (file)
@@ -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 = 
 #
index 8c6622d324a41796cc9e0e51a08066c37756350d..755d19fb55e89743ee6b49908267af3dd83283ea 100644 (file)
@@ -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
index c25d65831b4308e3e9364c1bb573ed19cbc80a71..3d654ae3df4cae97dd868c8c156b5f480897c917 100644 (file)
@@ -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 );
index eeb3c14189b93e830b9c5acdac3c4987430b5fc9..91824e20988593150d835ec14a92c8a0c21e757f 100644 (file)
@@ -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 <? max_i;
-       int nl_i = str.left_str( i + 1 ).index_i( '\n' );
-       if ( nl_i != -1 ) {
-           i = nl_i - 1;
-           str = str.nomid_str( nl_i, 1 );
-       }
-
-       if ( ( i != str.length_i() - 1 ) && ( nl_i == -1 ) ) {
-           while ( i && ( isalnum( str[ i ] ) 
-                          || ( nobreak_str.index_i( str[ i ] ) != -1 ) ) )
-               i--;
-
-           if ( !i ) { // no room left
-               if ( column_i_ > 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 );
 }
 
+
index ce33c6bc83d4d18a46f7244efdf7ee79c7bbb104..d28e90734010ce1fa8f763c9a8a31dcb292d51b5 100644 (file)
@@ -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;
index 62cc98910fd2453d5a68250336fb70921b55cb95..7b3262045c37a84bfdbc256d2b241427a4b3747f 100644 (file)
@@ -36,42 +36,32 @@ Midi_score::output_mudela( String filename_str )
        for ( PCursor<Midi_track*> 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<Midi_track*> 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<Midi_track*> 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;
 }
index f575ccfe68ca8f3445a6392e6d9675ee07a4d5ee..0efb7035010e89dd38b84bafa6c56b903304bd1c 100644 (file)
@@ -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";
 }