]> git.donarmstrong.com Git - lilypond.git/blobdiff - mi2mu/mudela-score.cc
patch::: 0.1.31: pats!
[lilypond.git] / mi2mu / mudela-score.cc
index 2a82a630c1720061eb7eabd3db58887d053e3e59..bf025d7ca0795a5b236db8b0c574aa34041141b4 100644 (file)
@@ -3,6 +3,7 @@
 //
 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
 
+#include <assert.h>
 #include "moment.hh"
 #include "duration.hh"
 #include "duration-convert.hh"
 #include "mudela-staff.hh"
 #include "mudela-stream.hh"
 
+//static Mudela_key key_c (0, 0);
+static Mudela_meter meter_4 (4, 2, 24, 8);
+// useconds per 4: 250000 === 60 4 per minute
+static Mudela_tempo tempo_60 (1000000);
+
 Mudela_score::Mudela_score (int format_i, int tracks_i, int tempo_i)
 {
-    format_i_ = format_i;
-    tracks_i_ = tracks_i;
-    tempo_i_ = tempo_i;
-    mudela_column_p_list_.bottom().add (new Mudela_column (this, Moment (0)));
+  format_i_ = format_i;
+  tracks_i_ = tracks_i;
+  tempo_i_ = tempo_i;
+  column_l_array_.push (new Mudela_column (this, Moment (0)));
+  //  mudela_key_l_ = &key_c;
+  mudela_key_l_ = 0;
+  mudela_meter_l_ = &meter_4;
+  mudela_tempo_l_ = &tempo_60;
 }
 
 Mudela_score::~Mudela_score()
 {
 }
 
-void 
+void
 Mudela_score::add_item (Mudela_item* mudela_item_p)
 {
-    mudela_staff_p_list_.bottom()->add_item (mudela_item_p);
+  mudela_staff_p_list_.bottom()->add_item (mudela_item_p);
 }
 
 void
 Mudela_score::add_staff (Mudela_staff* mudela_staff_p)
 {
-    mudela_staff_p_list_.bottom().add (mudela_staff_p);
+  mudela_staff_p_list_.bottom().add (mudela_staff_p);
 }
 
 Mudela_column*
-Mudela_score::mudela_column_l (Moment mom)
+Mudela_score::find_column_l (Moment mom)
 {
-    for  (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++) {
-       if  (i->at_mom() > mom) {
-           Mudela_column* p = new Mudela_column (this, mom);
-           i.insert (p);
-           return p;
-       }
-       if  (i->at_mom() == mom)
-           return *i;
+#if 0
+  // should do binary search
+  for (int i = 0; i < column_l_array_.size (); i++ )
+    if ( column_l_array_[i]->at_mom () == mom )
+      return column_l_array_[i];
+  return 0;
+#else
+  int upper_i = max (0, column_l_array_.size () - 1);
+  int lower_i = 0;
+  int i = 0; //upper_i;
+  while (1)
+    {
+      Moment i_mom = column_l_array_ [i]->at_mom ();
+      if (i_mom == mom)
+       return column_l_array_ [i];
+      if (mom < i_mom)
+       upper_i = i;
+      else
+       lower_i = i;
+      if ((upper_i == lower_i) || (i == column_l_array_.size () - 1))
+       {
+         // we don't do inserts
+         assert (0);
+         Mudela_column* col_p = new Mudela_column (this, mom);
+         column_l_array_.push (col_p);
+         return col_p;
+        }
+      i = (upper_i + lower_i + 1 ) / 2;
     }
+  assert (0);
+  return 0;
+#endif
+}
 
-    Mudela_column* p = new Mudela_column (this, mom);
-    mudela_column_p_list_.bottom().add (p);
-    return p;
+Mudela_column*
+Mudela_score::get_column_l (Moment mom)
+{
+  if ( column_l_array_ [column_l_array_.size() - 1]->at_mom () > mom )
+    {
+      error (_("ugh"));
+      exit (1);
+    }
+  if ( column_l_array_[column_l_array_.size() - 1]->at_mom () < mom )
+    column_l_array_.push (new Mudela_column (this, mom));
+
+  return column_l_array_ [column_l_array_.size() - 1];
 }
 
 void
 Mudela_score::output (String filename_str)
 {
-    LOGOUT(NORMAL_ver) << "Lily output to " << filename_str << " ..." << endl;
-    
-    // ugh, ugly midi type 1 fix
-    if  ( (mudela_staff_p_list_.size() == 1) && !mudela_staff_p_list_.top()->number_i_)
-       mudela_staff_p_list_.top()->number_i_ = 1;
-
-    int track_i = 0;
-    Mudela_stream mudela_stream (filename_str);
-    for  (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++) {
-       LOGOUT(NORMAL_ver) << "track " << track_i++ << ": " << flush;
-       i->output (mudela_stream);
-       mudela_stream << "\n";
-       LOGOUT(NORMAL_ver) << endl;
+  LOGOUT(NORMAL_ver) << _("Lily output to ") << filename_str << " ..." << endl;
+
+  // ugh, ugly midi type 1 fix
+  if  ( (mudela_staff_p_list_.size() == 1) && !mudela_staff_p_list_.top()->number_i_)
+    mudela_staff_p_list_.top()->number_i_ = 1;
+
+  int track_i = 0;
+  Mudela_stream mudela_stream (filename_str);
+  for  (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++)
+    {
+      LOGOUT(NORMAL_ver) << _("track ") << track_i++ << ": " << flush;
+      i->output (mudela_stream);
+      mudela_stream << "\n";
+      LOGOUT(NORMAL_ver) << endl;
     }
 
-    mudela_stream << "\\score{\n";
-    if  (mudela_staff_p_list_.size() > 1)
-       mudela_stream << "<\n\\multi 3;\n";
-    for  (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++) {
-       if  ( (mudela_staff_p_list_.size() != 1) 
+  mudela_stream << "\\score{\n";
+  if  (mudela_staff_p_list_.size() > 1)
+    mudela_stream << "\\multi 3 < \\type Staff\n";
+  for  (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++)
+    {
+      if  ( (mudela_staff_p_list_.size() != 1)
            &&  (i == mudela_staff_p_list_.top()))
-           continue;
-       mudela_stream << "\\melodic{ ";
-       mudela_stream << "\\$" << i->id_str();
-       mudela_stream << " }\n";
+       continue;
+      mudela_stream << "< \\melodic{ ";
+      mudela_stream << "\\$" << i->id_str();
+      mudela_stream << " } >\n";
     }
-    if  (mudela_staff_p_list_.size() > 1)
-       mudela_stream << ">\n";
+  if  (mudela_staff_p_list_.size() > 1)
+    mudela_stream << ">\n";
 
-    mudela_stream << "\\paper{}\n";
+  mudela_stream << "\\paper{}\n";
 
-    mudela_stream << "\\midi{ ";
-       // let's not use silly 0 track
-       mudela_staff_p_list_.bottom()->mudela_tempo_p_->output (mudela_stream);
-    mudela_stream << "}\n";
+  mudela_stream << "\\midi{\n";
+  // let's not use silly 0 track
+  mudela_staff_p_list_.bottom()->mudela_tempo_l_->output (mudela_stream);
+  mudela_stream << "}\n";
 
-    mudela_stream << "}\n";
+  mudela_stream << "}\n";
 }
 
 void
 Mudela_score::process()
 {
-    LOGOUT(NORMAL_ver) << "\nProcessing..." << endl;
-       
-    LOGOUT(DEBUG_ver) << "columns\n";
-    for  (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++)
-       LOGOUT(DEBUG_ver) << "At: " << i->at_mom() << "\n";
-
-    settle_columns();
-    filter_tempo();
-    quantify_columns();
-    quantify_durations();
-
-    LOGOUT(NORMAL_ver) << "\nCreating voices..." << endl;
-    int track_i = 0;
-    for  (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++)  {
-       LOGOUT(NORMAL_ver) << "track " << track_i++ << ": " << flush;
-       i->process();
-       LOGOUT(NORMAL_ver) << endl;
+  LOGOUT(NORMAL_ver) << _("\nProcessing...") << endl;
+
+  LOGOUT(DEBUG_ver) << "columns\n";
+  //  for  (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++)
+  //   LOGOUT(DEBUG_ver) << "At: " << i->at_mom() << "\n";
+
+  settle_columns();
+  filter_tempo();
+  quantify_columns();
+  quantify_durations();
+
+  LOGOUT(NORMAL_ver) << _("\nCreating voices...") << endl;
+  int track_i = 0;
+  for  (PCursor<Mudela_staff*> i (mudela_staff_p_list_); i.ok(); i++)
+    {
+      LOGOUT(NORMAL_ver) << _("track ") << track_i++ << ": " << flush;
+      i->process();
+      LOGOUT(NORMAL_ver) << endl;
     }
 }
 
 void
 Mudela_score::filter_tempo()
 {
-    LOGOUT(NORMAL_ver) << "\nNOT Filtering tempo..." << endl;
+  LOGOUT(NORMAL_ver) << _("\nNOT Filtering tempo...") << endl;
 }
 
 void
 Mudela_score::quantify_columns()
 {
-    // ugh
-    if  (Duration_convert::no_quantify_b_s) {
-       LOGOUT(NORMAL_ver) << "\nNOT Quantifying columns..." << endl;
-       return;
+  // ugh
+  if  (Duration_convert::no_quantify_b_s)
+    {
+      LOGOUT(NORMAL_ver) << _("\nNOT Quantifying columns...") << endl;
+      return;
     }
 
-    LOGOUT(NORMAL_ver) << "\nQuantifying columns..." << endl;
-
-    int n = 32 >? Duration_convert::no_smaller_than_i_s;
-    Moment s = Moment (1, n);
-    Moment sh = Moment (1, 2 * n);
-    for  (int i = 0; i < column_l_array_.size(); i++) {
-//     Moment mom = column_l_array_[ i ]->at_mom();
-//     column_l_array_[ i ]->at_mom_ = Duration_convert::dur2_mom (dur);
-       column_l_array_[ i ]->at_mom_ =
-//         s * (int) ( (sh + column_l_array_[ i ]->at_mom()) / s);
-           s * (int) ( (column_l_array_[ i ]->at_mom()) / s);
-       LOGOUT(NORMAL_ver) << '.';
-    } 
-    LOGOUT(NORMAL_ver) << endl;
+  LOGOUT(NORMAL_ver) << _("\nQuantifying columns...") << endl;
+
+  int current_bar_i = 0;
+  Moment bar_mom = mudela_meter_l_->bar_mom();
+
+  int n = 5 >? Duration_convert::no_smaller_than_i_s;
+  n = Duration_convert::type2_i (n);
+  Moment s = Moment (1, n);
+  Moment sh = Moment (1, 2 * n);
+  for  (int i = 0; i < column_l_array_.size(); i++)
+    {
+      column_l_array_ [i]->at_mom_ =
+       s * Moment( (int) ( (column_l_array_ [i]->at_mom()) / s));
+
+      int bar_i = (int) (column_l_array_ [i]->at_mom () / bar_mom) + 1;
+      if (bar_i > current_bar_i)
+       {
+         LOGOUT (NORMAL_ver) << '[' << bar_i << ']' << flush;
+         current_bar_i = bar_i;
+       }
+    }
+  LOGOUT(NORMAL_ver) << endl;
 }
 
 void
 Mudela_score::quantify_durations()
 {
-//    LOGOUT(NORMAL_ver) << "\nQuantifying durations..." << endl;
+  //    LOGOUT(NORMAL_ver) << "\nQuantifying durations..." << endl;
 }
 
 void
 Mudela_score::settle_columns()
 {
-//    LOGOUT(NORMAL_ver) << "\nNOT Settling columns..." << endl;
-//    return;
-    LOGOUT(NORMAL_ver) << "\nSettling columns..." << endl;
-
-    assert (!column_l_array_.size());
-    int n = mudela_column_p_list_.size();
-// huh?
-//    column_l_array_.set_size (n);
-    for  (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++)
-       column_l_array_.push (*i);
-
-    int start_i = 0;
-    int end_i = 0;
-    Moment start_mom = 0;
-    Duration smallest_dur;
-    smallest_dur.type_i_ =  64;
-    Moment const noise_mom = Duration_convert::dur2_mom (smallest_dur)
-       / Moment (2);
-    for  (int i = 0; i < n; i++) {
-       if  (!start_i) {
-           start_i = end_i = i;
-           start_mom = column_l_array_[ i ]->at_mom();
-           continue;
+  //    LOGOUT(NORMAL_ver) << "\nNOT Settling columns..." << endl;
+  //    return;
+  LOGOUT(NORMAL_ver) << _("\nSettling columns...") << endl;
+
+#if 0
+  assert (!column_l_array_.size());
+  int n = mudela_column_p_list_.size();
+  // huh?
+  //    column_l_array_.set_size (n);
+  for  (PCursor<Mudela_column*> i (mudela_column_p_list_); i.ok(); i++)
+    column_l_array_.push (*i);
+#endif
+
+  int n = column_l_array_.size();
+
+  int start_i = 0;
+  int end_i = 0;
+  Moment start_mom = 0;
+  Duration smallest_dur;
+  smallest_dur.durlog_i_ =  6;
+  Moment const noise_mom = Duration_convert::dur2_mom (smallest_dur)
+    / Moment (2);
+  for  (int i = 0; i < n; i++)
+    {
+      if  (!start_i)
+       {
+         start_i = end_i = i;
+         start_mom = column_l_array_ [i]->at_mom();
+         continue;
        }
 
-       // find all columns within noise's distance
-       while  ( (i < n)
-           &&  (column_l_array_[ i ]->at_mom() - start_mom < noise_mom))
-           end_i = ++i;
+      // find all columns within noise's distance
+      while  ( (i < n)
+              &&  (column_l_array_ [i]->at_mom() - start_mom < noise_mom))
+       end_i = ++i;
 
-       // bluntly set all to time of first in group
-       for  (int j = start_i; j < end_i; j++)
-           column_l_array_[ j ]->at_mom_ = start_mom;
+      // bluntly set all to time of first in group
+      for  (int j = start_i; j < end_i; j++)
+       column_l_array_ [j]->at_mom_ = start_mom;
 
-       start_i = end_i = 0;
+      start_i = end_i = 0;
     }
 }
-