+pl 27.jcn2
+ - grand renaming: Duration vs Moment / Rational
+
pl 27.jcn1
- complete redo of chord and chord name code
- small fixes
MAJOR_VERSION=1
MINOR_VERSION=1
PATCH_LEVEL=27
-MY_PATCH_LEVEL=jcn1
+MY_PATCH_LEVEL=jcn2
# use the above to send patches: MY_PATCH_LEVEL is always empty for a
# released version.
Duration dur = mom2standardised_dur (mom);
// if (!dur.mom () || (dur.mom () == mom))
- if (!dur.length () || (dur.length () == mom))
+ if (!dur.length_mom () || (dur.length_mom () == mom))
return dur;
assert (midi_as_plet_b_s);
// dur.set_plet (type_mom, Duration::division_1_i_s / 4);
// Moment as_plet_mom = mom / dur.mom ();
- Moment as_plet_mom = mom / dur.length ();
+ Moment as_plet_mom = mom / dur.length_mom ();
as_plet_mom *= dur.plet_.mom ();
long num = as_plet_mom.num ();
long den = as_plet_mom.den ();
Duration dur = mom2standardised_dur (mom);
- if (dur.length () == mom)
+ if (dur.length_mom () == mom)
return dur;
return mom2_dur (mom);
plet_.type_i_ *= m.den_i ();
}
-// ugh, what's this?
-// i should be called "mom ()", ... or at least "length_mom ()"
Moment
-Duration::length () const
+Duration::length_mom () const
{
return Duration_convert::dur2_mom (*this);
}
static bool duration_type_b (int t);
void set_ticks (int ticks_i );
- Moment length () const ; // zo naai mij
+ Moment length_mom () const ;
static int division_1_i_s;
/// Logarithm of the base duration.
#include "musical-request.hh"
#include "bar.hh"
#include "beam.hh"
-#include "grouping.hh"
+#include "rhythmic-grouping.hh"
#include "rest.hh"
#include "stem.hh"
#include "debug.hh"
void
Auto_beam_engraver::begin_beam ()
{
- DOUT << String ("starting autobeam at: ") + now_moment ().str () + "\n";
+ DOUT << String ("starting autobeam at: ") + now_mom ().str () + "\n";
beam_p_ = new Beam;
grouping_p_ = new Rhythmic_grouping;
void
Auto_beam_engraver::end_beam ()
{
- DOUT << String ("ending autobeam at: ") + now_moment ().str () + "\n";
+ DOUT << String ("ending autobeam at: ") + now_mom ().str () + "\n";
if (beam_p_->stems_.size () < 2)
{
DOUT << "junking autombeam: less than two stems\n";
consider_end_and_begin ();
}
mult_i_ = m;
- grouping_p_->add_child (start, rhythmic_req->duration ());
+ grouping_p_->add_child (start, rhythmic_req->length_mom ());
stem_l->flag_i_ = rhythmic_req->duration_.durlog_i_;
beam_p_->add_stem (stem_l);
- Moment now = now_moment ();
+ Moment now = now_mom ();
last_add_mom_ = now;
- extend_mom_ = extend_mom_ >? now + rhythmic_req->duration ();
+ extend_mom_ = extend_mom_ >? now + rhythmic_req->length_mom ();
}
}
}
{
if (beam_p_)
{
- Moment now = now_moment ();
+ Moment now = now_mom ();
if ((extend_mom_ < now)
|| ((extend_mom_ == now) && (last_add_mom_ != now )))
{
create_bar ();
bar_p_->type_str_ = bar_req_l_->type_str_;
}
- else if (!now_moment ())
+ else if (!now_mom ())
{
create_bar ();
bar_p_->type_str_ = "";
Timing_translator *timer = dynamic_cast<Timing_translator*>(tr);
Time_description *time = &timer->time_;
- if (!time->whole_in_measure_ && !time->cadenza_b_ && now_moment () > Moment (0))
+ if (!time->whole_in_measure_ && !time->cadenza_b_ && now_mom () > Moment (0))
{
create_items (0);
#include "beam-engraver.hh"
#include "musical-request.hh"
#include "beam.hh"
-#include "grouping.hh"
+#include "rhythmic-grouping.hh"
#include "stem.hh"
#include "warn.hh"
#include "time-description.hh"
if (!grouping_p_->child_fit_b (start))
{
String s (_ ("please fix me") + ": "
- + _f ("stem at %s doesn't fit in beam", now_moment ().str ()));
+ + _f ("stem at %s doesn't fit in beam", now_mom ().str ()));
if (info.req_l_)
info.req_l_->warning(s);
}
else
{
- grouping_p_->add_child (start, rhythmic_req->duration ());
+ grouping_p_->add_child (start, rhythmic_req->length_mom ());
stem_l->flag_i_ = rhythmic_req->duration_.durlog_i_;
beam_p_->add_stem (stem_l);
}
#include "stem.hh"
#include "paper-def.hh"
#include "lookup.hh"
-#include "grouping.hh"
+#include "rhythmic-grouping.hh"
Beam::Beam ()
{
Partial_measure_req::Partial_measure_req (Moment m)
{
- duration_ =m;
+ length_mom_ =m;
}
bool
{
Partial_measure_req *p = dynamic_cast <Partial_measure_req *> (r);
- return p&& p->duration_ == duration_;
+ return p&& p->length_mom_ == length_mom_;
}
void
Partial_measure_req::do_print() const
{
- DOUT << duration_;
+ DOUT << length_mom_;
}
{
Tempo_req *t = dynamic_cast <Tempo_req *> (r);
- return t&& t->dur_.length()== dur_.length () && metronome_i_ == t->metronome_i_;
+ return t&& t->dur_.length_mom ()== dur_.length_mom () && metronome_i_ == t->metronome_i_;
}
}
Moment
-Global_translator::now_moment () const
+Global_translator::now_mom () const
{
return now_mom_;
}
-/*
- grouping.cc -- implement Rhythmic_grouping
-
- source file of the GNU LilyPond music typesetter
-
- (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-*/
-
-#include "debug.hh"
-#include "grouping.hh"
-#include "interval.hh"
-
-void
-Rhythmic_grouping::init()
-{
- interval_ = 0;
- children.clear();
-}
-
-void
-Rhythmic_grouping::OK() const
-{
-#ifndef NDEBUG
- assert (bool (children.size()) != bool (interval_));
-
- for (int i= 0; i < children.size(); i++)
- {
- children[i]->OK();
- if (i>0)
- assert (children[i-1]->interval().right ==
- children[i]->interval().left);
- }
-#endif
-}
-
-Moment
-Rhythmic_grouping::length() const
-{
- return interval().length ();
-}
-
-MInterval
-Rhythmic_grouping::interval() const
-{
- if (interval_)
- return *interval_;
- else
- return
- MInterval (children[0]->interval().left,
- children.top()->interval ().right);
-}
-
-void
-Rhythmic_grouping::split (Rhythmic_grouping r)
-{
- if (interval_)
- return ;
-
- r.intersect (interval());
- split (r.intervals());
-
- for (int i= 0; i < children.size(); i++)
- {
- if (!children[i]->interval_)
- {
- Rhythmic_grouping here (r);
- children[i]->split (here);
- }
- }
-}
-
-
-Array<MInterval>
-Rhythmic_grouping::intervals()
-{
- Array<MInterval> r;
- if (interval_ || children.size() == 1)
- {
- MInterval i (interval());
- MInterval r1(i), r2(i);
- r1.right = r2.left = i.center();
- r.push (r1); r.push (r2);
- }
- else
- {
- for (int i=0; i < children.size(); i++)
- r.push (children[i]->interval());
- }
- return r;
-}
-
-void
-Rhythmic_grouping::intersect (MInterval t)
-{
- if (interval_)
- {
- interval_->intersect (t);
- return;
- }
-
- for (int i=0; i < children.size(); i++)
- {
- MInterval inter = intersection (t, children[i]->interval());
- if (inter.empty_b() || inter.length () <= Rational (0))
- {
- delete children[i];
- children[i] =0;
- }
- else
- {
- children[i]->intersect (t);
- }
- }
- for (int i=0; i < children.size();)
- {
- if (!children[i])
- children.del (i);
- else
- i++;
- }
-
-}
-
-/**
- Put our children in branches of #this#.
- The min and max time intervals coincide with elements of #splitpoints#
-
- I really should be documenting what is happening here, but I find
- that difficult, since I don't really understand what's going on here.
-
- */
-void
-Rhythmic_grouping::split (Array<MInterval> splitpoints)
-{
- //check on splitpoints..
- int j = 0, i = 0, starti = 0, startj = 0;
-
- Array<Rhythmic_grouping*> ch;
- while (1)
- {
- if (i >= children.size() || j >= splitpoints.size ())
- break;
-
- assert (
- children[starti]->interval().left== splitpoints[startj].left);
- if (children[i]->interval().right < splitpoints[j].right)
- {
- i ++;
- }
- else if (children[i]->interval().right > splitpoints[j].right)
- {
- j ++;
- }
- else
- {
-
- if (i == starti)
- {
- ch.push (children[i]);
- }
- else
- {
- Rhythmic_grouping *newchild=new Rhythmic_grouping (
- children.slice (starti, i+1));
-
- ch.push (newchild);
- }
- i ++;
- j++;
- starti = i;
- startj = j;
-
-
- }
- }
- if (ch.size() != 1)
- children = ch;
-}
-
-
-Rhythmic_grouping::Rhythmic_grouping (MInterval t, int n)
-{
- init();
- if (n == 1 || !n)
- {
- interval_ = new MInterval (t);
- return;
- }
- Moment dt = t.length()/Rational (n);
- MInterval basic = MInterval (t.left, t.left+dt);
- for (int i= 0; i < n; i++)
- children.push (new Rhythmic_grouping (dt*Rational (i) + basic));
-}
-
-
-Rhythmic_grouping::Rhythmic_grouping (Array<Rhythmic_grouping*> r)
- :children (r)
-{
- interval_ =0;
-}
-
-Rhythmic_grouping::~Rhythmic_grouping()
-{
- junk();
-}
-
-void
-Rhythmic_grouping::copy (Rhythmic_grouping const&s)
-{
- interval_ = (s.interval_)? new MInterval (*s.interval_) : 0;
- for (int i=0; i < s.children.size(); i++)
- children.push (new Rhythmic_grouping (*s.children[i]));
-}
-
-void
-Rhythmic_grouping::operator=(Rhythmic_grouping const &s)
-{
- junk();
- copy (s);
-}
-
-Rhythmic_grouping::Rhythmic_grouping (Rhythmic_grouping const&s)
-{
- init();
- copy (s);
-}
-
-void
-Rhythmic_grouping::junk()
-{
- delete interval_;
- for (int i=0; i < children.size(); i++)
- delete children[i];
- init();
-}
-
-void
-Rhythmic_grouping::print() const
-{
-#ifndef NPRINT
- DOUT << "{ \n";
- if (interval_)
- DOUT <<" Interval "<< interval_->str();
- for (int i=0; i < children.size(); i++)
- {
- children[i]->print();
- }
- DOUT << "}\n";
-#endif
-}
-
-bool
-Rhythmic_grouping::child_fit_b (Moment start)
-{
- if (children.size())
- return (children.top()->interval ().right== start);
-
- return true;
-}
-
-void
-Rhythmic_grouping::add_child (Moment start, Moment len)
-{
- Moment stop = start+len;
- assert (child_fit_b (start));
- children.push (new Rhythmic_grouping (MInterval (start, stop)));
-}
-
-Rhythmic_grouping::Rhythmic_grouping()
-{
- interval_ =0;
-}
-
-int
-min_elt (Array<int> v)
-{
- int i = 1000; // ugh
- for (int j = 0 ; j < v.size(); j++)
- i = i <? v[j];
- return i;
-}
-
-Array<int>
-Rhythmic_grouping::generate_beams (Array<int> flags, int &flagidx)
-{
- assert (!interval_) ;
-
- Array< Array<int> > children_beams;
- for (int i=0; i < children.size(); i++)
- {
- Array<int> child_beams;
- if (children[i]->interval_)
- {
- int f = flags[flagidx++];
- child_beams.push (f);
- }
- else
- {
- child_beams = children[i]->
- generate_beams (flags, flagidx);
- }
- children_beams.push (child_beams);
- }
- Array<int> beams;
- int lastm, m, nextm;
- for (int i=0; i < children_beams.size(); i++)
- {
- bool add_left = (i >0);
- bool add_right = (i < children_beams.size() -1);
-
- if (!i)
- m = min_elt (children_beams[i]);
- if (add_right)
- nextm = min_elt (children_beams[i+1]);
-
- if (children_beams[i].size() == 1)
- {
- if (add_right)
- beams.push (m);
- if (add_left)
- beams.push (m);
- }
- else
- {
- if (add_left)
- beams.push (lastm <? m);
- beams.concat (children_beams[i]);
- if (add_right)
- beams.push (m <? nextm);
- }
- lastm = m;
- m = nextm;
- }
- assert (!(beams.size()%2));
- return beams;
-}
-
-void
-Rhythmic_grouping::translate (Moment m)
-{
- if (interval_)
- *interval_ += m;
- else
- for (int i=0; i < children.size(); i++)
- children[i]->translate (m);
-}
-
-void
-Rhythmic_grouping::extend (MInterval m) const
-{
- assert (m.left >= interval().left);
- while (m.right >interval().right)
- {
- Array<Rhythmic_grouping*> a (children);
- for (int i=0; i < a.size(); i++)
- {
- a[i] =new Rhythmic_grouping (*children[i]);
- a[i]->translate (children.top()->interval ().right);
- }
- ((Rhythmic_grouping*)this)->children.concat (a);
- }
- assert (m.right <= interval().right);
- OK();
-}
-
-Rhythmic_grouping
-parse_grouping (Array<int> beat_i_arr, Array<Moment> elt_length_arr)
-{
- Moment here =0;
- assert (beat_i_arr.size() == elt_length_arr.size ());
-
- Array<Rhythmic_grouping*> children;
- for (int i=0; i < beat_i_arr.size(); i++)
- {
- Moment last = here;
- here += elt_length_arr[i] * Moment (beat_i_arr[i]);
- children.push (
- new Rhythmic_grouping (MInterval (last, here),
- beat_i_arr[i]));
- }
- return Rhythmic_grouping (children);
-}
-
class Partial_measure_req : public Timing_req {
public:
- Moment duration_;
+ Moment length_mom_;
Partial_measure_req (Moment);
REQUESTMETHODS(Partial_measure_req);
protected:
- virtual Moment now_moment () const;
+ virtual Moment now_mom () const;
virtual Global_translator *global_l() { return this; }
};
-/*
- grouping.hh -- part of GNU LilyPond
-
- (c) 1996--1998 Han-Wen Nienhuys
-*/
-
-#ifndef GROUPING_HH
-#define GROUPING_HH
-
-#include "minterval.hh"
-#include "array.hh"
-
-/** data structure which represents rhythmic units this is a tree. It groupes notes according to rules
-
- TODO Documentation. Unhairing
- */
-struct Rhythmic_grouping {
- Array<Rhythmic_grouping*> children;
- MInterval *interval_;
-
-
- Array<MInterval> intervals();
- MInterval interval() const;
- Moment length() const;
- void intersect (MInterval);
-
- void operator=(Rhythmic_grouping const&);
- Rhythmic_grouping (Rhythmic_grouping const&);
- Rhythmic_grouping (MInterval, int n=1);
- Rhythmic_grouping();
- Rhythmic_grouping (Array<Rhythmic_grouping*>);
- ~Rhythmic_grouping();
-
- void add_child (Moment start, Moment len);
- bool child_fit_b (Moment start);
- void split (Rhythmic_grouping r);
- void split (Array<MInterval>);
- void split (int n);
-
- void print() const;
- void OK() const;
-
- Array<int> generate_beams (Array<int>, int&);
-
- /** multiply self to span #i#.
- In implementation, this isn't really const, but conceptually it is.
- */
- void extend (MInterval i) const;
- void translate (Moment);
-private:
- void init();
- void junk();
- void copy (Rhythmic_grouping const&);
-};
-
-
-Rhythmic_grouping parse_grouping (Array<int> beat_i_arr, Array<Moment> elt_length_arr);
-
-
-#endif
Midi_def();
~Midi_def();
- Real duration_to_seconds_f (Moment);
+ Real length_mom_to_seconds_f (Moment);
int get_tempo_i (Moment moment);
void print() const;
void set_tempo (Moment moment, int count_per_minute_i);
Midi_note (Audio_item* audio_item_l);
- Moment duration () const;
+ Moment length_mom () const;
int pitch_i () const;
virtual String str () const;
Simultaneous_music(Music_list *);
virtual Musical_pitch to_relative_octave (Musical_pitch);
- virtual Moment duration () const;
+ virtual Moment length_mom () const;
};
virtual Musical_pitch to_relative_octave (Musical_pitch);
Sequential_music(Music_list*);
- virtual Moment duration () const;
+ virtual Moment length_mom () const;
};
#endif // Music_sequence_HH
VIRTUAL_COPY_CONS(Music);
Music_wrapper (Music_wrapper const&);
- virtual Moment duration () const;
+ virtual Moment length_mom () const;
virtual ~Music_wrapper ();
virtual Musical_pitch to_relative_octave (Musical_pitch);
virtual Musical_pitch to_relative_octave (Musical_pitch);
/// The duration of this piece of music
- virtual Moment duration () const;
+ virtual Moment length_mom () const;
virtual ~Music(){}
void print() const;
bool do_equal_b (Request*) const;
void compress (Moment);
- virtual Moment duration() const;
+ virtual Moment length_mom () const;
static int compare (Rhythmic_req const&,Rhythmic_req const&);
REQUESTMETHODS(Rhythmic_req);
};
/** convert a duration to an idealspacing
influence using the geometric_ and paratime_signatures.
*/
- Real duration_to_dist (Moment, Real) const;
+ Real length_mom_to_dist (Moment, Real) const;
Real geometric_spacing (Moment) const;
Real arithmetic_constant (Moment minimal_mom) const;
Real arithmetic_spacing (Moment mom,Real constant) const;
virtual void do_print () const;
virtual void transpose (Musical_pitch p);
- virtual Moment duration () const;
+ virtual Moment length_mom () const;
virtual Musical_pitch to_relative_octave (Musical_pitch p);
VIRTUAL_COPY_CONS(Music);
};
class Request_chord_iterator : public Music_iterator {
Request_chord * elt_l () const;
/**
- cache elt_l ()->duration ().
+ cache elt_l ()->length_mom ().
*/
- Moment elt_duration_;
+ Moment elt_length_mom_;
bool last_b_;
public:
--- /dev/null
+/*
+ rhythmic-grouping.hh -- part of GNU LilyPond
+
+ (c) 1996--1998 Han-Wen Nienhuys
+*/
+
+#ifndef RHYTHMIC_GROUPING_HH
+#define RHYTHMIC_GROUPING_HH
+
+#include "minterval.hh"
+#include "array.hh"
+
+/** data structure which represents rhythmic units this is a tree. It groupes notes according to rules
+
+ TODO Documentation. Unhairing
+ */
+struct Rhythmic_grouping {
+ Array<Rhythmic_grouping*> children;
+ MInterval *interval_;
+
+
+ Array<MInterval> intervals();
+ MInterval interval() const;
+ Moment length_mom () const;
+ void intersect (MInterval);
+
+ void operator=(Rhythmic_grouping const&);
+ Rhythmic_grouping (Rhythmic_grouping const&);
+ Rhythmic_grouping (MInterval, int n=1);
+ Rhythmic_grouping();
+ Rhythmic_grouping (Array<Rhythmic_grouping*>);
+ ~Rhythmic_grouping();
+
+ void add_child (Moment start, Moment len);
+ bool child_fit_b (Moment start);
+ void split (Rhythmic_grouping r);
+ void split (Array<MInterval>);
+ void split (int n);
+
+ void print() const;
+ void OK() const;
+
+ Array<int> generate_beams (Array<int>, int&);
+
+ /** multiply self to span #i#.
+ In implementation, this isn't really const, but conceptually it is.
+ */
+ void extend (MInterval i) const;
+ void translate (Moment);
+private:
+ void init();
+ void junk();
+ void copy (Rhythmic_grouping const&);
+};
+
+
+Rhythmic_grouping parse_grouping (Array<int> beat_i_arr, Array<Moment> elt_length_arr);
+
+
+#endif // RHYTHMIC_GROUPING_HH
#define METERGRAV_HH
#include "engraver.hh"
#include "time-description.hh"
-#include "grouping.hh"
+#include "rhythmic-grouping.hh"
/**
generate time_signatures.
#include "translator.hh"
#include "time-description.hh"
-#include "grouping.hh"
+#include "rhythmic-grouping.hh"
#include "parray.hh"
class Timing_translator : public virtual Translator
*/
Music_output_def *output_def_l () const;
Scalar get_property (String, Translator_group **) const;
- virtual Moment now_moment () const;
+ virtual Moment now_mom () const;
protected:
enum {
}
Real
-Midi_def::duration_to_seconds_f (Moment mom)
+Midi_def::length_mom_to_seconds_f (Moment mom)
{
if (!mom)
return 0;
}
Moment
-Midi_note::duration () const
+Midi_note::length_mom () const
{
- Moment m = dynamic_cast <Rhythmic_req *> (audio_item_l_->req_l_)->duration ();
+ Moment m = dynamic_cast <Rhythmic_req *> (audio_item_l_->req_l_)->length_mom ();
if (m < Moment (1, 1000))
{
warning (_ ("silly duration"));
void
Midi_walker::do_start_note (Midi_note* note_p)
{
- Moment stop_mom = note_p->duration() + ptr ()->audio_column_l_->at_mom ();
+ Moment stop_mom = note_p->length_mom () + ptr ()->audio_column_l_->at_mom ();
for (int i=0; i < stop_note_queue.size(); i++)
{
if (stop_note_queue[i].val->pitch_i() == note_p->pitch_i ())
{
if (multi_measure_req_l_)
if (!multi_measure_req_l_->equal_b (mr)
- || rest_moments_[START] != now_moment ())
+ || rest_moments_[START] != now_mom ())
return false;
multi_measure_req_l_ = mr;
- rest_moments_[START] = now_moment ();
+ rest_moments_[START] = now_mom ();
- rest_moments_[STOP] = rest_moments_[START] + multi_measure_req_l_->duration_.length ();
+ rest_moments_[STOP] = rest_moments_[START] + multi_measure_req_l_->duration_.length_mom ();
return true;
}
return false;
void
Multi_measure_rest_engraver::do_pre_move_processing ()
{
- Moment now (now_moment ());
+ Moment now (now_mom ());
Time_description const *time = get_staff_info().time_C_;
if (mmrest_p_ && (now >= rest_moments_[START])
&& !time->whole_in_measure_
Multi_measure_rest_engraver::do_post_move_processing ()
{
Time_description const *time = get_staff_info().time_C_;
- Moment now (now_moment ());
+ Moment now (now_mom ());
if (mmrest_p_ && !time->whole_in_measure_)
{
#include "main.hh"
Moment
-Simultaneous_music::duration () const
+Simultaneous_music::length_mom () const
{
Moment dur = 0;
for (iter (music_p_list_p_->top(), i); i.ok (); i++)
- dur = dur >? i->duration ();
+ dur = dur >? i->length_mom ();
return dur;
}
}
Moment
-Sequential_music::duration () const
+Sequential_music::length_mom () const
{
Moment last=0;
for (iter (music_p_list_p_->top(), i); i.ok (); i++)
{
- last += i->duration ();
+ last += i->length_mom ();
}
return last;
}
Moment
-Music_wrapper::duration () const
+Music_wrapper::length_mom () const
{
- return element_p_->duration ();
+ return element_p_->length_mom ();
}
}
Moment
-Music::duration () const
+Music::length_mom () const
{
return 0;
}
int
Rhythmic_req::compare (Rhythmic_req const &r1, Rhythmic_req const &r2)
{
- return (r1.duration () - r2.duration ());
+ return (r1.length_mom () - r2.length_mom ());
}
bool
Moment
-Rhythmic_req::duration () const
+Rhythmic_req::length_mom () const
{
- return duration_.length ();
+ return duration_.length_mom ();
}
void
Skip_req::do_print () const
{
#ifndef NPRINT
- DOUT << "duration: " << duration ();
+ DOUT << "duration: " << length_mom ();
#endif
}
}
Real
-Paper_def::duration_to_dist (Moment d,Real k) const
+Paper_def::length_mom_to_dist (Moment d,Real k) const
{
return arithmetic_spacing (d,k);
}
$$-> assign_translator ($2);
}
| midi_body tempo_request ';' {
- $$->set_tempo ($2->dur_.length (), $2->metronome_i_);
+ $$->set_tempo ($2->dur_.length_mom (), $2->metronome_i_);
delete $2;
}
| midi_body error {
$$ = new Cadenza_req ($2);
}
| PARTIAL duration_length {
- $$ = new Partial_measure_req ($2->length ());
+ $$ = new Partial_measure_req ($2->length_mom ());
delete $2;
}
| CLEF STRING {
return true;
Music_sequence* alt = r->alternative_p_;
- Moment stop_mom = now_moment () + r->repeat_p_->duration ();
+ Moment stop_mom = now_mom () + r->repeat_p_->length_mom ();
for (PCursor<Music*> i (alt->music_p_list_p_->top ()); i.ok () && (i != alt->music_p_list_p_->bottom ()); i++)
{
- stop_mom += i->duration ();
+ stop_mom += i->length_mom ();
if (dynamic_cast<Simultaneous_music *> (alt))
break;
}
- Moment alt_mom = now_moment () + r->repeat_p_->duration ();
+ Moment alt_mom = now_mom () + r->repeat_p_->length_mom ();
/*
TODO:
figure out what we don't want.
{
alternative_music_arr_.push (i.ptr ());
alternative_start_mom_arr_.push (alt_mom);
- alternative_stop_mom_arr_.push (alt_mom + i->duration ());
+ alternative_stop_mom_arr_.push (alt_mom + i->length_mom ());
if (!dynamic_cast<Simultaneous_music *> (alt))
- alt_mom += i->duration ();
+ alt_mom += i->length_mom ();
}
return true;
}
void
Repeat_engraver::acknowledge_element (Score_element_info i)
{
- Moment now = now_moment ();
+ Moment now = now_mom ();
if (Note_column *c = dynamic_cast<Note_column *> (i.elem_l_))
{
for (int i = 0; i < volta_p_arr_.size (); i++)
void
Repeat_engraver::do_process_requests ()
{
- Moment now = now_moment ();
+ Moment now = now_mom ();
Bar_engraver* bar_engraver_l = dynamic_cast <Bar_engraver*>
(daddy_grav_l ()->get_simple_translator ("Bar_engraver"));
for (int i = bar_b_arr_.size (); i < repeated_music_arr_.size (); i++)
void
Repeat_engraver::do_pre_move_processing ()
{
- Moment now = now_moment ();
+ Moment now = now_mom ();
for (int i = bar_b_arr_.size (); i--; )
{
if (bar_b_arr_[i])
{
#if 0
Time_description const *time = get_staff_info().time_C_;
- Moment now = now_moment ();
+ Moment now = now_mom ();
for (int i = volta_p_arr_.size (); i--; )
{
if ((now > alternative_stop_mom_arr_[i])
else if (alternative_iter_p_)
return alternative_iter_p_->next_moment () + here_mom_;
// huh?
-// return repeated_music_l ()->repeat_p_->duration ()
+// return repeated_music_l ()->repeat_p_->length_mom ()
// * Moment (repeated_music_l ()->repeats_i_)
-// + repeated_music_l ()->alternative_p_->duration () + here_mom_;
- return repeated_music_l ()->alternative_p_->duration () + here_mom_;
+// + repeated_music_l ()->alternative_p_->length_mom () + here_mom_;
+ return repeated_music_l ()->alternative_p_->length_mom () + here_mom_;
}
bool
repeat_iter_p_ = 0;
alternative_iter_p_ = dynamic_cast<Music_list_iterator*>
(get_iterator_p ((Music*)repeated_music_l ()->alternative_p_));
- here_mom_ += repeated_music_l ()->repeat_p_->duration ();
+ here_mom_ += repeated_music_l ()->repeat_p_->length_mom ();
}
else if (alternative_iter_p_)
{
unfold_i_--;
repeat_iter_p_ = get_iterator_p (repeated_music_l ()->repeat_p_);
// urg, assume same length alternatives for now...
-// here_mom_ += repeated_music_l ()->alternative_p_->music_p_list_p_->top ()->duration ();
+// here_mom_ += repeated_music_l ()->alternative_p_->music_p_list_p_->top ()->length_mom ();
/*
URG
this is *wrong* but at least it doesn't dump core
how to intercept this...
*/
- here_mom_ += repeated_music_l ()->alternative_p_->duration ();
+ here_mom_ += repeated_music_l ()->alternative_p_->length_mom ();
}
}
}
}
Moment
-Repeated_music::duration () const
+Repeated_music::length_mom () const
{
Moment m;
if (repeat_p_)
- m += repeat_p_->duration ();
+ m += repeat_p_->length_mom ();
if (alternative_p_)
- m += alternative_p_->duration ();
+ m += alternative_p_->length_mom ();
return m;
}
void
Request_chord_iterator::construct_children()
{
- elt_duration_ =elt_l ()->duration ();
+ elt_length_mom_ =elt_l ()->length_mom ();
get_req_translator_l();
}
bool
Request_chord_iterator::ok() const
{
- return (elt_duration_ && !last_b_) || first_b_;
+ return (elt_length_mom_ && !last_b_) || first_b_;
}
{
Moment m (0);
if (!first_b_)
- m = elt_duration_;
+ m = elt_length_mom_;
return m;
}
Request_chord_iterator::do_print() const
{
#ifndef NPRINT
- DOUT << "duration: " << elt_duration_;
+ DOUT << "duration: " << elt_length_mom_;
#endif
}
first_b_ = false;
}
- if (mom >= elt_duration_)
+ if (mom >= elt_length_mom_)
last_b_ = true;
}
--- /dev/null
+/*
+ rhythmic-grouping.cc -- implement Rhythmic_grouping
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
+#include "debug.hh"
+#include "rhythmic-grouping.hh"
+#include "interval.hh"
+
+void
+Rhythmic_grouping::init()
+{
+ interval_ = 0;
+ children.clear();
+}
+
+void
+Rhythmic_grouping::OK() const
+{
+#ifndef NDEBUG
+ assert (bool (children.size()) != bool (interval_));
+
+ for (int i= 0; i < children.size(); i++)
+ {
+ children[i]->OK();
+ if (i>0)
+ assert (children[i-1]->interval().right ==
+ children[i]->interval().left);
+ }
+#endif
+}
+
+Moment
+Rhythmic_grouping::length_mom () const
+{
+ return interval().length ();
+}
+
+MInterval
+Rhythmic_grouping::interval() const
+{
+ if (interval_)
+ return *interval_;
+ else
+ return
+ MInterval (children[0]->interval().left,
+ children.top()->interval ().right);
+}
+
+void
+Rhythmic_grouping::split (Rhythmic_grouping r)
+{
+ if (interval_)
+ return ;
+
+ r.intersect (interval());
+ split (r.intervals());
+
+ for (int i= 0; i < children.size(); i++)
+ {
+ if (!children[i]->interval_)
+ {
+ Rhythmic_grouping here (r);
+ children[i]->split (here);
+ }
+ }
+}
+
+
+Array<MInterval>
+Rhythmic_grouping::intervals()
+{
+ Array<MInterval> r;
+ if (interval_ || children.size() == 1)
+ {
+ MInterval i (interval());
+ MInterval r1(i), r2(i);
+ r1.right = r2.left = i.center();
+ r.push (r1); r.push (r2);
+ }
+ else
+ {
+ for (int i=0; i < children.size(); i++)
+ r.push (children[i]->interval());
+ }
+ return r;
+}
+
+void
+Rhythmic_grouping::intersect (MInterval t)
+{
+ if (interval_)
+ {
+ interval_->intersect (t);
+ return;
+ }
+
+ for (int i=0; i < children.size(); i++)
+ {
+ MInterval inter = intersection (t, children[i]->interval());
+ if (inter.empty_b() || inter.length () <= Moment (0))
+ {
+ delete children[i];
+ children[i] =0;
+ }
+ else
+ {
+ children[i]->intersect (t);
+ }
+ }
+ for (int i=0; i < children.size();)
+ {
+ if (!children[i])
+ children.del (i);
+ else
+ i++;
+ }
+
+}
+
+/**
+ Put our children in branches of #this#.
+ The min and max time intervals coincide with elements of #splitpoints#
+
+ I really should be documenting what is happening here, but I find
+ that difficult, since I don't really understand what's going on here.
+
+ */
+void
+Rhythmic_grouping::split (Array<MInterval> splitpoints)
+{
+ //check on splitpoints..
+ int j = 0, i = 0, starti = 0, startj = 0;
+
+ Array<Rhythmic_grouping*> ch;
+ while (1)
+ {
+ if (i >= children.size() || j >= splitpoints.size ())
+ break;
+
+ assert (
+ children[starti]->interval().left== splitpoints[startj].left);
+ if (children[i]->interval().right < splitpoints[j].right)
+ {
+ i ++;
+ }
+ else if (children[i]->interval().right > splitpoints[j].right)
+ {
+ j ++;
+ }
+ else
+ {
+
+ if (i == starti)
+ {
+ ch.push (children[i]);
+ }
+ else
+ {
+ Rhythmic_grouping *newchild=new Rhythmic_grouping (
+ children.slice (starti, i+1));
+
+ ch.push (newchild);
+ }
+ i ++;
+ j++;
+ starti = i;
+ startj = j;
+
+
+ }
+ }
+ if (ch.size() != 1)
+ children = ch;
+}
+
+
+Rhythmic_grouping::Rhythmic_grouping (MInterval t, int n)
+{
+ init();
+ if (n == 1 || !n)
+ {
+ interval_ = new MInterval (t);
+ return;
+ }
+ Moment dt = t.length ()/Moment (n);
+ MInterval basic = MInterval (t.left, t.left+dt);
+ for (int i= 0; i < n; i++)
+ children.push (new Rhythmic_grouping (dt*Moment (i) + basic));
+}
+
+
+Rhythmic_grouping::Rhythmic_grouping (Array<Rhythmic_grouping*> r)
+ :children (r)
+{
+ interval_ =0;
+}
+
+Rhythmic_grouping::~Rhythmic_grouping()
+{
+ junk();
+}
+
+void
+Rhythmic_grouping::copy (Rhythmic_grouping const&s)
+{
+ interval_ = (s.interval_)? new MInterval (*s.interval_) : 0;
+ for (int i=0; i < s.children.size(); i++)
+ children.push (new Rhythmic_grouping (*s.children[i]));
+}
+
+void
+Rhythmic_grouping::operator=(Rhythmic_grouping const &s)
+{
+ junk();
+ copy (s);
+}
+
+Rhythmic_grouping::Rhythmic_grouping (Rhythmic_grouping const&s)
+{
+ init();
+ copy (s);
+}
+
+void
+Rhythmic_grouping::junk()
+{
+ delete interval_;
+ for (int i=0; i < children.size(); i++)
+ delete children[i];
+ init();
+}
+
+void
+Rhythmic_grouping::print() const
+{
+#ifndef NPRINT
+ DOUT << "{ \n";
+ if (interval_)
+ DOUT <<" Interval "<< interval_->str();
+ for (int i=0; i < children.size(); i++)
+ {
+ children[i]->print();
+ }
+ DOUT << "}\n";
+#endif
+}
+
+bool
+Rhythmic_grouping::child_fit_b (Moment start)
+{
+ if (children.size())
+ return (children.top()->interval ().right== start);
+
+ return true;
+}
+
+void
+Rhythmic_grouping::add_child (Moment start, Moment len)
+{
+ Moment stop = start+len;
+ assert (child_fit_b (start));
+ children.push (new Rhythmic_grouping (MInterval (start, stop)));
+}
+
+Rhythmic_grouping::Rhythmic_grouping()
+{
+ interval_ =0;
+}
+
+int
+min_elt (Array<int> v)
+{
+ int i = 1000; // ugh
+ for (int j = 0 ; j < v.size(); j++)
+ i = i <? v[j];
+ return i;
+}
+
+Array<int>
+Rhythmic_grouping::generate_beams (Array<int> flags, int &flagidx)
+{
+ assert (!interval_) ;
+
+ Array< Array<int> > children_beams;
+ for (int i=0; i < children.size(); i++)
+ {
+ Array<int> child_beams;
+ if (children[i]->interval_)
+ {
+ int f = flags[flagidx++];
+ child_beams.push (f);
+ }
+ else
+ {
+ child_beams = children[i]->
+ generate_beams (flags, flagidx);
+ }
+ children_beams.push (child_beams);
+ }
+ Array<int> beams;
+ int lastm, m, nextm;
+ for (int i=0; i < children_beams.size(); i++)
+ {
+ bool add_left = (i >0);
+ bool add_right = (i < children_beams.size() -1);
+
+ if (!i)
+ m = min_elt (children_beams[i]);
+ if (add_right)
+ nextm = min_elt (children_beams[i+1]);
+
+ if (children_beams[i].size() == 1)
+ {
+ if (add_right)
+ beams.push (m);
+ if (add_left)
+ beams.push (m);
+ }
+ else
+ {
+ if (add_left)
+ beams.push (lastm <? m);
+ beams.concat (children_beams[i]);
+ if (add_right)
+ beams.push (m <? nextm);
+ }
+ lastm = m;
+ m = nextm;
+ }
+ assert (!(beams.size()%2));
+ return beams;
+}
+
+void
+Rhythmic_grouping::translate (Moment m)
+{
+ if (interval_)
+ *interval_ += m;
+ else
+ for (int i=0; i < children.size(); i++)
+ children[i]->translate (m);
+}
+
+void
+Rhythmic_grouping::extend (MInterval m) const
+{
+ assert (m.left >= interval().left);
+ while (m.right >interval().right)
+ {
+ Array<Rhythmic_grouping*> a (children);
+ for (int i=0; i < a.size(); i++)
+ {
+ a[i] =new Rhythmic_grouping (*children[i]);
+ a[i]->translate (children.top()->interval ().right);
+ }
+ ((Rhythmic_grouping*)this)->children.concat (a);
+ }
+ assert (m.right <= interval().right);
+ OK();
+}
+
+Rhythmic_grouping
+parse_grouping (Array<int> beat_i_arr, Array<Moment> elt_length_arr)
+{
+ Moment here =0;
+ assert (beat_i_arr.size() == elt_length_arr.size ());
+
+ Array<Rhythmic_grouping*> children;
+ for (int i=0; i < beat_i_arr.size(); i++)
+ {
+ Moment last = here;
+ here += elt_length_arr[i] * Moment (beat_i_arr[i]);
+ children.push (
+ new Rhythmic_grouping (MInterval (last, here),
+ beat_i_arr[i]));
+ }
+ return Rhythmic_grouping (children);
+}
+
{
if (Rhythmic_req *rq = dynamic_cast <Rhythmic_req *> (announce_info_arr_[i].req_l_))
{
- musical_column_l_->add_duration (rq->duration());
+ musical_column_l_->add_duration (rq->length_mom ());
}
}
Engraver_group_engraver::do_announces();
return ;
}
*mlog << '\n' << _("Interpreting music...") << flush;
- trans_p->last_mom_ = music_p_->duration ();
+ trans_p->last_mom_ = music_p_->length_mom ();
Music_iterator * iter = Music_iterator::static_get_iterator_p (music_p_, trans_p);
{
delete iter_p_;
iter_p_ =0;
- Moment elt_time = cursor_p_->ptr()->duration ();
+ Moment elt_time = cursor_p_->ptr()->length_mom ();
here_mom_ += elt_time;
cursor_p_->next();
}
if (delta_t)
{
Real k= paper_l()->arithmetic_constant (context_shortest_arr[i]);
- durational_distance = paper_l()->duration_to_dist (delta_t,k);
+ durational_distance = paper_l()->length_mom_to_dist (delta_t,k);
}
symbol_distance += -cols_[i+1].width_[LEFT];
}
Moment delta_t = scol_l (i+1)->when() - scol_l (i)->when ();
Real k= paper_l()->arithmetic_constant(context_shortest);
- Real dist = paper_l()->duration_to_dist (shortest_playing_len, k);
+ Real dist = paper_l()->length_mom_to_dist (shortest_playing_len, k);
dist *= (double)(delta_t / shortest_playing_len);
/*
String long_str = get_property ("instrument", 0);
String str = get_property ("instr", 0);
- if (now_moment () > Moment (0) && str.length_i ())
+ if (now_mom () > Moment (0) && str.length_i ())
long_str = str;
if (long_str.empty_b ())
if (Note_head *nh = dynamic_cast<Note_head *> (i.elem_l_))
{
Note_req * m = dynamic_cast<Note_req* > (i.req_l_);
- now_heads_.push (CHead_melodic_tuple (nh, m, now_moment()+ m->duration ()));
+ now_heads_.push (CHead_melodic_tuple (nh, m, now_mom()+ m->length_mom ()));
}
}
{
if (req_l_)
{
- Moment now = now_moment ();
+ Moment now = now_mom ();
Link_array<Note_head> nharr;
stopped_heads_.clear ();
Tie_engraver::do_post_move_processing ()
{
req_l_ =0;
- Moment now = now_moment ();
+ Moment now = now_mom ();
while (past_notes_pq_.size () && past_notes_pq_.front ().end_ < now)
past_notes_pq_.delmin ();
}
s += "at ";
s += when_.str ();
s +="\ntime_signature " + (whole_per_measure_/one_beat_).str () +":" +
- (Rational (Rational (1)/one_beat_)).str ();
+ (Moment (Moment (1)/one_beat_)).str ();
s += "\nposition " + to_str (bars_i_) + ":"+ whole_in_measure_.str () +"\n}\n";
return s;
}
void
Time_description::add (Moment dt)
{
- assert (dt >= Rational (0));
+ assert (dt >= Moment (0));
when_ += dt;
whole_in_measure_ += dt;
Time_description::set_time_signature (int l, int o)
{
assert (o);
- one_beat_ = Rational (1)/Moment (o);
+ one_beat_ = Moment (1)/Moment (o);
whole_per_measure_ = Moment (l) * one_beat_;
}
String
Time_description::try_set_partial_str (Moment p) const
{
- if (p<Rational (0))
+ if (p<Moment (0))
return (_ ("partial measure must be non-negative"));
if (p > whole_per_measure_)
return (_ ("partial measure too large"));
}
else if (Partial_measure_req *pm = dynamic_cast <Partial_measure_req *> (tr_l))
{
- Moment m = pm->duration_;
+ Moment m = pm->length_mom_;
String error = time_.try_set_partial_str (m);
if (error.length_i ())
{
void
Timing_translator::do_creation_processing()
{
- time_.when_ = now_moment ();
+ time_.when_ = now_mom ();
}
void
Timing_translator::do_post_move_processing()
{
- time_.add (now_moment () - time_.when_);
+ time_.add (now_mom () - time_.when_);
}
void
void
Translator_group::terminate_translator (Translator*r_l)
{
- DOUT << "Removing " << classname (r_l) << " at " << now_moment () << '\n';
+ DOUT << "Removing " << classname (r_l) << " at " << now_mom () << '\n';
r_l->removal_processing();
Translator * trans_p =remove_translator_p (r_l);
Moment
-Translator::now_moment () const
+Translator::now_mom () const
{
- return daddy_trans_l_->now_moment ();
+ return daddy_trans_l_->now_mom ();
}
if (!dynamic_cast<Request_chord*> (el))
{
compressed_music_arr_.push (c);
- stop_moments_.push (now_moment () + c->duration ());
+ stop_moments_.push (now_mom () + c->length_mom ());
}
return true;
}
void
Tuplet_engraver::do_post_move_processing ()
{
- Moment now = now_moment ();
+ Moment now = now_mom ();
for (int i= started_span_p_arr_.size (); i--; )
{
if (now >= stop_moments_[i])