return r;
}
+
+/*
+ lookup with binsearch, return array index.
+*/
+template<class T>
+int
+binary_search (Array<T> const &table,
+ T const &key, int (*compare) (T const&, T const &),
+ int lo = 0,
+ int hi = -1
+ )
+{
+ int cmp;
+ int result;
+ if (hi < 0)
+ hi = table.size ();
+
+ /* binary search */
+ do
+ {
+ cmp = (lo + hi) / 2;
+
+ result = (*compare) (key, table[cmp]);
+
+ if (result < 0)
+ hi = cmp;
+ else
+ lo = cmp;
+ }
+ while (hi - lo > 1);
+ if (! (*compare) (key, table[lo]))
+ {
+ return lo;
+ }
+ else
+ return -1; /* not found */
+}
+
template<class T>
int
binsearch_link_array (Link_array<T> const &arr, T *t,
- int (*compare) (T *const&,T *const&))
+ int (*compare) (T *const&,T *const&),
+ int lo = 0, int hi = -1 )
{
- int lo;
- int hi;
int cmp;
int result;
- lo = 0;
- hi = arr.size ();
+ if (hi< 0)
+ hi = arr.size ();
if (hi == 0)
return -1;
--- /dev/null
+
+\score {\notes \relative c'' <
+\context Staff = SA { \times 6/7 { [c8 c c c c c c] } }
+\context Staff = SB { \times 6/6 { [c c c c c c] } }
+>
+
+\paper { linewidth = -1. }
+}
--- /dev/null
+
+\score {
+\notes \relative c' <
+\context Staff = SA { c4. c8 \times 2/3 { [c8 c c] } }
+\context Staff = SB { c8 c c c c c }
+>
+
+\paper { linewidth = -1. }
+}
#ifndef KEYWORD_HH
#define KEYWORD_HH
+#include "array.hh"
+
/* for the keyword table */
struct Keyword_ent
{
- char const *name;
- int tokcode;
+ char const *name_;
+ int tokcode_;
};
/*
*/
struct Keyword_table
{
- Keyword_ent *table;
- int maxkey;
+ Array<Keyword_ent> table_;
+
Keyword_table (Keyword_ent *);
int lookup (char const *s) const;
};
static int rank_i (Grob*);
Paper_column (SCM);
- bool musical_b () const;
+ static bool musical_b (Grob *);
static Moment when_mom (Grob*);
static bool used_b (Grob*) ;
/* for qsort */
-int
- tabcmp (void const * p1, void const * p2)
+int tabcmp (Keyword_ent const &p1, Keyword_ent const &p2)
{
- return strcmp (( (Keyword_ent const *) p1)->name,
- ((Keyword_ent const *) p2)->name);
+ return strcmp (p1.name_, p2.name_);
}
Keyword_table::Keyword_table (Keyword_ent *tab)
{
- table = tab;
-
- /* count keywords */
- for (maxkey = 0; table[maxkey].name; maxkey++)
- ;
+ while (tab->name_)
+ {
+ table_.push (*tab++);
+ }
- /* sort them */
- qsort (table, maxkey, sizeof (Keyword_ent), tabcmp);
+ table_.sort (tabcmp);
}
-/*
- lookup with binsearch, return tokencode.
-*/
int
Keyword_table::lookup (char const *s) const
{
- int lo;
- int hi;
- int cmp;
- int result;
- lo = 0;
- hi = maxkey;
-
- /* binary search */
- do
- {
- cmp = (lo + hi) / 2;
-
- result = strcmp (s, table[cmp].name);
-
- if (result < 0)
- hi = cmp;
- else
- lo = cmp;
- }
- while (hi - lo > 1);
- if (!strcmp (s, table[lo].name))
- {
- return table[lo].tokcode;
- }
+ Keyword_ent e ;
+ e.name_ = s;
+ int idx = binary_search (table_, e, tabcmp);
+ if (idx >= 0)
+ return table_[idx].tokcode_;
else
- return -1; /* not found */
+ return -1;
}
-
}
return s;
}
-
+
bool
-Paper_column::musical_b () const
+Paper_column::musical_b (Grob *me)
{
- SCM m = get_grob_property ("shortest-starter-duration");
+ SCM m = me->get_grob_property ("shortest-starter-duration");
Moment s (0);
if (unsmob_moment (m))
{
s = *unsmob_moment (m);
}
return s != Moment (0);
+
}
-
+
bool
Paper_column::used_b (Grob*me)
{
me->set_extent_callback (SCM_EOL, Y_AXIS) ;
}
+#if 0
+struct Note_run
+{
+ Array<int> idxes;
+ int start, end;
+ Moment duration;
+ int count;
+};
+
+int
+column_compare (Grob *const &t1, Grob *const &t2)
+{
+ return Moment::compare (Paper_column::when_mom (t1),
+ Paper_column::when_mom (t2));
+}
+
+
+Note_run
+run_length (Moment dt, int i, Array<Moment> const &moms,
+ Link_array<Note_run> runs)
+{
+ int k = 0;
+ Array<int> idxes;
+
+ idxes.push (i);
+ while (1)
+ {
+ Moment next = moms[i] + dt;
+ while (i < moms.size () && moms[i] < next)
+ i++;
+ if (i == moms.size () || moms[i] != next)
+ break;
+
+ idxes.push (i);
+ k++;
+ }
+
+ Moment dur = idxes.size ()
+}
+
+void
+find_runs (Grob*me, Link_array<Grob> cols)
+{
+ Link_array<Grob> filter_cols;
+ Array<Moment> col_moments;
+ for (int i = 0; i < cols.size (); i++)
+ {
+ Moment w = Paper_column::when_mom (cols[i]);
+
+ if (!w.grace_mom_ && Paper_column::musical_b (cols[i]))
+ {
+ filter_cols.push (cols[i]);
+ col_moments.push (w);
+ }
+ }
+
+ Moment end_mom = col_moments.top ();
+ for (int i = 0; i < col_moments.size () ; i++)
+ {
+ for (int j = i+1; j < col_moments.size (); j++)
+ {
+ Moment dt = Paper_column::col_momentsfilter_cols
+ }
+ }
+}
+#endif
+
/*
The algorithm is partly taken from :
int n = 0;
for (int i =0 ; i < cols.size (); i++)
{
- if (dynamic_cast<Paper_column*> (cols[i])->musical_b ())
+ if (Paper_column::musical_b (cols[i]))
{
Moment *when = unsmob_moment (cols[i]->get_grob_property ("when"));
left_distance = gh_scm2double (gh_cdr (hint));
}
// 2nd condition should be (i+1 < col_count ()), ie. not the last column in score. FIXME
- else if (!lc->musical_b () && i+1 < cols.size ())
+ else if (!Paper_column::musical_b (lc) && i+1 < cols.size ())
{
left_distance= default_bar_spacing (me,lc,rc,shortest <? base_shortest_duration);
}
- else if (lc->musical_b ())
+ else if (Paper_column::musical_b ( lc))
{
left_distance = note_spacing (me,lc, rc, shortest <? base_shortest_duration);
}
/*
don't want to create too much extra space for accidentals
*/
- if (rc->musical_b ())
+ if (Paper_column::musical_b (rc))
{
if (to_boolean (rc->get_grob_property ("contains-grace")))
right_dist *= gh_scm2double (rc->get_grob_property ("before-grace-spacing-factor")); // fixme.
}
Moment delta_t = Paper_column::when_mom (rc) - Paper_column::when_mom (lc);
Real dist = get_duration_space (me, shortest_playing_len, shortest);
- dist *= (double) (delta_t / shortest_playing_len);
+
+
+ /*
+ ugh: 0.1 is an arbitrary distance.
+ */
+ dist *= (double) (delta_t.main_part_ / shortest_playing_len.main_part_)
+ + 0.1 * (double) (delta_t.grace_mom_ / shortest_playing_len.main_part_);
-
- #(define (grace-beam-space-function multiplicity)
- (* (if (<= multiplicity 3) 0.816 0.844) 0.8))
-
-
- #(define (make-text-checker text)
- (lambda (elt) (equal? text (ly-get-grob-property elt 'text))))
+#(define (grace-beam-space-function multiplicity)
+ (* (if (<= multiplicity 3) 0.816 0.844) 0.8))
startGraceMusic = {
-
-%{
-from GraceContext
- Stem \override #'flag-style = #"grace"
- Stem \override #'stem-length = #6.0
- Stem \override #'direction = #1
-
- NoteHead \override #'font-relative-size = #-1
- Stem \override #'font-relative-size = #-1
- Stem \override #'stem-shorten = #'(0)
- Beam \override #'font-relative-size = #-1
- TextScript \override #'font-relative-size = #-1
- Slur \override #'font-relative-size = #-1
- Accidentals \override #'font-relative-size = #-1
- Beam \override #'thickness = #0.3
- Beam \override #'space-function = #(lambda (x) 0.5)
-
- Stem \override #'lengths = #(map (lambda (x) (* 0.8 x)) '(3.5 3.5 3.5 4.5 5.0))
- Stem \override #'beamed-lengths =
- #'(0.0 2.5 2.0 1.5)
- Stem \override #'beamed-minimum-lengths
- = #(map (lambda (x) (* 0.8 x)) '(0.0 2.5 2.0 1.5))
-%}
-
-
- \property Voice.NoteHead \override #'font-relative-size = #-1
+ \property Voice.Stem \override #'direction = #1
\property Voice.Stem \override #'length = #6
+ \property Voice.Stem \override #'lengths =
+ #(map (lambda (x) (* 0.8 x)) '(3.5 3.5 3.5 4.5 5.0))
\property Voice.Stem \override #'beamed-lengths =
#(map (lambda (x) (* 1.25 x)) '(0.0 2.5 2.0 1.5))
\property Voice.Stem \override #'beamed-minimum-lengths =
#(map (lambda (x) (* 1.25 x)) '(0.0 1.5 1.25 1.0))
- \property Voice.Beam \override #'space-function = #grace-beam-space-function
- \property Voice.fontSize = #-2
\property Voice.Stem \override #'no-stem-extend = ##t
+ \property Voice.Stem \override #'flag-style = #"grace"
-% \property Voice.Stem \override #'flag-style = #"grace"
+ \property Voice.Beam \override #'space-function = #grace-beam-space-function
+ \property Voice.Beam \override #'thickness = #0.3
+
+ % must use staff. Accidentals should also be smaller.
+ \property Staff.fontSize = #-2
}
stopGraceMusic = {
-% \property Voice.Stem \revert #'flag-style
- \property Voice.Stem \override #'no-stem-extend = ##f
- \property Voice.Stem \revert #'length
+ \property Voice.Beam \revert #'space-function
+ \property Voice.Beam \revert #'thickness
+
+ \property Voice.Stem \revert #'flag-style
+ \property Voice.Stem \revert #'no-stem-extend
\property Voice.Stem \revert #'beamed-lengths
\property Voice.Stem \revert #'beamed-minimum-lengths
- \property Voice.Beam \revert #'space-function
- \property Voice.fontSize \unset
+ \property Voice.Stem \revert #'lengths
+ \property Voice.Stem \revert #'length
+ \property Voice.Stem \revert #'direction
+
+ \property Staff.fontSize \unset
}