// 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;
/**
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;
MAJOR_VERSION = 0
MINOR_VERSION = 0
-PATCH_LEVEL = 18
+PATCH_LEVEL = 19
# use to send patches, always empty for released version:
MY_PATCH_LEVEL =
#
#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
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 );
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();
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;
}
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()
{
*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
}
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 );
}
+
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;
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;
}
#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()
{
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;
// 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";
}
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";
}