From dd02678ddca0116e4e98fd18e36fcb908e340283 Mon Sep 17 00:00:00 2001 From: fred Date: Wed, 27 Mar 2002 02:03:39 +0000 Subject: [PATCH] lilypond-1.5.17 --- CHANGES | 29 ++++++++ flower/include/rational.hh | 4 +- flower/rational.cc | 10 --- input/bugs/cross-staff-tie.ly | 18 +++++ input/bugs/knee.ly | 40 +++++++++++ input/template/piano-dynamics.ly | 96 +++++++++++++++++++++++++ lily/duration.cc | 1 - lily/font-metric.cc | 2 +- lily/grob.cc | 4 +- lily/include/duration.hh | 2 +- lily/include/font-metric.hh | 2 +- lily/include/grob.hh | 2 +- lily/include/input-smob.hh | 3 +- lily/include/ly-smobs.icc | 15 ---- lily/include/lyric-phrasing-engraver.hh | 2 +- lily/include/molecule.hh | 2 +- lily/include/moment.hh | 2 +- lily/include/music-output-def.hh | 2 +- lily/include/music.hh | 2 +- lily/include/pitch.hh | 2 +- lily/include/score.hh | 2 +- lily/include/smobs.hh | 15 +++- lily/include/translator-def.hh | 2 +- lily/include/translator.hh | 2 +- lily/molecule.cc | 2 +- lily/moment.cc | 2 +- lily/music-output-def.cc | 2 +- lily/music.cc | 2 +- lily/pitch.cc | 2 +- lily/scm-hash.cc | 2 +- lily/score.cc | 2 +- lily/syllable-group.cc | 2 +- lily/translator-def.cc | 2 +- lily/translator.cc | 2 +- scripts/midi2ly.py | 87 +++++++++++++--------- 35 files changed, 280 insertions(+), 88 deletions(-) create mode 100644 input/bugs/cross-staff-tie.ly create mode 100644 input/bugs/knee.ly create mode 100644 input/template/piano-dynamics.ly diff --git a/CHANGES b/CHANGES index 7eac9d8357..f2983b1216 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,32 @@ +1.5.16.hjj2 +=========== + +* Emacs-mode: Inserting tags + +* Enable python2.1/Python.h + +1.5.16.hwn1 +=========== + +* Add unfold-repeats function (Rune Zedeler!) to standard init SCM file. + +* Bugfix: spacing is no longer confused by coupled clefs, where one of the +clefs is loose, and the other not. + +* Robustness fix for Slur. Don't crash if attachment not set. + +* Arpeggios can now have arrows on the top or bottom to determine +their direction. (MF code by Chris Jackson) + +* Symbol cache bugfix in system-start-delimiter.cc -- may switch +symbol cache off for gcc 2.96? + +* MikTeX PDF detection bugfix (Mats Bengtsson) + +* Some more random hacking at midi2ly.py. (jcn1) + +* Inline unsmob_XXX functions. Speedup of 6% on wtk1-fugue2. + 1.5.15.jcn1 =========== diff --git a/flower/include/rational.hh b/flower/include/rational.hh index 995700c55c..9373b48448 100644 --- a/flower/include/rational.hh +++ b/flower/include/rational.hh @@ -59,8 +59,10 @@ public: Rational (int, int); Rational (double); Rational (Rational const&r) { copy (r);} + Rational &operator = (Rational const &r) { + copy (r); return *this; + } - Rational &operator = (Rational const &); Rational &operator *= (Rational); Rational &operator /= (Rational); Rational &operator += (Rational); diff --git a/flower/rational.cc b/flower/rational.cc index b2b7c898ee..42e0c0a97c 100644 --- a/flower/rational.cc +++ b/flower/rational.cc @@ -271,16 +271,6 @@ Rational::operator -= (Rational r) return (*this += r); } -/* - be paranoid about overiding libg++ stuff - */ -Rational & -Rational::operator = (Rational const &r) -{ - copy (r); - return *this; -} - String Rational::str () const { diff --git a/input/bugs/cross-staff-tie.ly b/input/bugs/cross-staff-tie.ly new file mode 100644 index 0000000000..7dca649913 --- /dev/null +++ b/input/bugs/cross-staff-tie.ly @@ -0,0 +1,18 @@ + + + +\version "1.4.8" +\score { \notes + \context PianoStaff < + \context Staff = up { \clef G + c'2 ~ \translator Staff=down c' + } + \context Staff = down { \clef F + s1 + } + > + \paper { } +} + + + diff --git a/input/bugs/knee.ly b/input/bugs/knee.ly new file mode 100644 index 0000000000..4f90edf59b --- /dev/null +++ b/input/bugs/knee.ly @@ -0,0 +1,40 @@ +\header { + +texidoc=" +gives + +@example + | | + | | + +-- | --+ + +----+----+ + | + | + +instead of the desired + + | | + | | + | --+ + +----+----+ + +-- + | + | + +@end example +" + +} + +\score { + \notes\relative c' { + c16 c''8 c16 + + % it's very helpful to have this one too, + % because a fix is likely to break + + c,, c'' c,, cc + } + \paper { linewidth = -1 } +} + \ No newline at end of file diff --git a/input/template/piano-dynamics.ly b/input/template/piano-dynamics.ly new file mode 100644 index 0000000000..59a0a08218 --- /dev/null +++ b/input/template/piano-dynamics.ly @@ -0,0 +1,96 @@ +\version "1.5.1" + +\header { + dedication = "dedication" + title = "Title" + subtitle = "Subtitle" + subsubtitle = "Subsubtitle" + composer = "Composer (xxxx-yyyy)" + opus = "Opus 0" + piece = "Piece I" + instrument = "Instrument" + arranger = "Arranger" + poet = "Poet" + texttranslator = "Translator" + copyright = "public domain" + enteredby = "jcn" + source = "urtext" +} + +upper = \notes\relative c'' { + a b c d +} + +lower = \notes\relative c { + a2 c +} + +dynamics = \notes { + \outputproperty #(make-type-checker 'dynamic-interface) + #'extra-offset = #'(0 . 2.5) + s2\fff\> s4 + \outputproperty #(make-type-checker 'dynamic-interface) + #'extra-offset = #'(0 . 2.5) + \!s\pp +} + +pedal = \notes { + s2\sustainDown s2\sustainUp +} + +\score { + \context PianoStaff < + \context Staff=upper \upper + \context Dynamics=dynamics \dynamics + \context Staff=lower < + \clef bass + \lower + > + \context Dynamics=pedal \pedal + > + \paper { + \translator { + \type "Engraver_group_engraver" + \name Dynamics + \consists "Output_property_engraver" + Generic_property_list = #generic-voice-properties + \consists "Property_engraver" + MinimumVerticalExtent = #'(-1 . 1) + + pedalSustainStrings = #'("Ped." "*Ped." "*") + pedalUnaCordaStrings = #'("una corda" "" "tre corde") + + \consists "Piano_pedal_engraver" + \consists "Script_engraver" + \consists "Dynamic_engraver" + \consists "Text_engraver" + + TextScript \override #'font-relative-size = #1 + TextScript \override #'font-shape = #'italic + + \consists "Skip_req_swallow_translator" + + \consistsend "Axis_group_engraver" + } + \translator { + \PianoStaffContext + \accepts Dynamics + VerticalAlignment \override #'forced-distance = #7 + } + } + \midi { + \translator { + \type "Performer_group_performer" + \name Dynamics + Generic_property_list = #generic-voice-properties + + \consists "Piano_pedal_performer" + \consists "Span_dynamic_performer" + \consists "Dynamic_performer" + } + \translator { + \PianoStaffContext + \accepts Dynamics + } + } +} diff --git a/lily/duration.cc b/lily/duration.cc index 6476466774..f6ffb9145b 100644 --- a/lily/duration.cc +++ b/lily/duration.cc @@ -80,7 +80,6 @@ Duration::str () const IMPLEMENT_TYPE_P (Duration, "duration?"); -IMPLEMENT_UNSMOB (Duration, duration); SCM Duration::mark_smob (SCM) diff --git a/lily/font-metric.cc b/lily/font-metric.cc index d22da509ee..0fcf96fc11 100644 --- a/lily/font-metric.cc +++ b/lily/font-metric.cc @@ -121,7 +121,7 @@ Font_metric::print_smob (SCM s, SCM port, scm_print_state *) } -IMPLEMENT_UNSMOB (Font_metric, metrics); + IMPLEMENT_SMOBS (Font_metric); IMPLEMENT_DEFAULT_EQUAL_P (Font_metric); IMPLEMENT_TYPE_P (Font_metric, "font-metric?"); diff --git a/lily/grob.cc b/lily/grob.cc index 82b1771516..f55ee2f8e2 100644 --- a/lily/grob.cc +++ b/lily/grob.cc @@ -141,7 +141,7 @@ Grob::get_grob_property (SCM sym) const /* Remove the value associated with KEY, and return it. The result is - that a next call will yield SCM_UNDEFINED (and not the underlying + that a next call will yield SCM_EOL (and not the underlying `basic' property. */ SCM @@ -768,7 +768,7 @@ Grob::fixup_refpoint (SCM smob) ****************************************************/ -IMPLEMENT_UNSMOB (Grob, grob); + IMPLEMENT_SMOBS (Grob); IMPLEMENT_DEFAULT_EQUAL_P (Grob); diff --git a/lily/include/duration.hh b/lily/include/duration.hh index bdb988a1c3..7324349fdc 100644 --- a/lily/include/duration.hh +++ b/lily/include/duration.hh @@ -45,7 +45,7 @@ private: #include "compare.hh" INSTANTIATE_COMPARE (Duration, Duration::compare); -Duration*unsmob_duration (SCM); +DECLARE_UNSMOB(Duration,duration); // int compare (Array*, Array*); #endif // DURATION_HH diff --git a/lily/include/font-metric.hh b/lily/include/font-metric.hh index 87137221c3..d3ae05da69 100644 --- a/lily/include/font-metric.hh +++ b/lily/include/font-metric.hh @@ -34,7 +34,7 @@ protected: Font_metric (); }; -Font_metric * unsmob_metrics (SCM s); +DECLARE_UNSMOB(Font_metric, metrics); #endif /* FONT_METRIC_HH */ diff --git a/lily/include/grob.hh b/lily/include/grob.hh index e1820f9d07..0cabf6e0e1 100644 --- a/lily/include/grob.hh +++ b/lily/include/grob.hh @@ -174,7 +174,7 @@ public: DECLARE_SCHEME_CALLBACK (fixup_refpoint, (SCM)); }; -Grob * unsmob_grob (SCM); +DECLARE_UNSMOB(Grob,grob); #endif // STAFFELEM_HH diff --git a/lily/include/input-smob.hh b/lily/include/input-smob.hh index 2cd9462d5d..c38c240edf 100644 --- a/lily/include/input-smob.hh +++ b/lily/include/input-smob.hh @@ -12,9 +12,10 @@ #include "input.hh" #include "lily-guile.hh" +#include "smobs.hh" SCM make_input (Input spot); -Input *unsmob_input (SCM); +Input *unsmob_input(SCM); extern Input dummy_input_global; diff --git a/lily/include/ly-smobs.icc b/lily/include/ly-smobs.icc index 69c7d2ecfe..f5b8f62c10 100644 --- a/lily/include/ly-smobs.icc +++ b/lily/include/ly-smobs.icc @@ -13,13 +13,6 @@ #include "smobs.hh" -#define IMPLEMENT_UNSMOB(CL, name) \ -CL * \ -unsmob_ ## name ( SCM s) \ -{ \ -return CL::unsmob (s); \ -} - #define IMPLEMENT_TYPE_P(CL, FUNCNAME)\ void init_type_p_ ## CL ()\ {\ @@ -64,14 +57,6 @@ SCM CL::smobbed_self () const \ \ return s; \ } \ -CL * \ -CL::unsmob (SCM s) \ -{ \ - if (SCM_NIMP (s) && SCM_CELL_TYPE (s) == smob_tag_) \ - return (CL*) SCM_CELL_WORD_1 (s); \ - else \ - return 0; \ -} \ size_t \ CL::free_smob (SCM ses) \ { \ diff --git a/lily/include/lyric-phrasing-engraver.hh b/lily/include/lyric-phrasing-engraver.hh index 269d5a9658..8a336e55ae 100644 --- a/lily/include/lyric-phrasing-engraver.hh +++ b/lily/include/lyric-phrasing-engraver.hh @@ -118,7 +118,7 @@ private: DECLARE_SIMPLE_SMOBS (Syllable_group,); } ; -Syllable_group * unsmob_voice_entry (SCM); +DECLARE_UNSMOB(Syllable_group,voice_entry); #endif // LYRIC_PHRASING_ENGRAVER_HH diff --git a/lily/include/molecule.hh b/lily/include/molecule.hh index a8a3425279..214e3181a4 100644 --- a/lily/include/molecule.hh +++ b/lily/include/molecule.hh @@ -86,7 +86,7 @@ public: }; -Molecule *unsmob_molecule (SCM); +DECLARE_UNSMOB(Molecule,molecule); SCM fontify_atom (Font_metric*, SCM atom); Molecule create_molecule (SCM brew_molecule); diff --git a/lily/include/moment.hh b/lily/include/moment.hh index 4993b7691f..54a8ad9cd7 100644 --- a/lily/include/moment.hh +++ b/lily/include/moment.hh @@ -58,7 +58,7 @@ IMPLEMENT_ARITHMETIC_OPERATOR (Moment, * ); ostream & operator << ( ostream &,Moment const &); -Moment * unsmob_moment (SCM); +DECLARE_UNSMOB(Moment,moment); int compare (Moment const&,Moment const&); INSTANTIATE_COMPARE (Moment const&, Moment::compare); diff --git a/lily/include/music-output-def.hh b/lily/include/music-output-def.hh index 9128c2b2ed..bc7e5c73a0 100644 --- a/lily/include/music-output-def.hh +++ b/lily/include/music-output-def.hh @@ -46,5 +46,5 @@ public: DECLARE_SMOBS (Music_output_def,); }; -Music_output_def* unsmob_music_output_def (SCM); +DECLARE_UNSMOB(Music_output_def,music_output_def); #endif // Music_output_DEF_HH diff --git a/lily/include/music.hh b/lily/include/music.hh index 2ce12fed36..500eb003dc 100644 --- a/lily/include/music.hh +++ b/lily/include/music.hh @@ -68,7 +68,7 @@ protected: }; -Music * unsmob_music (SCM); +DECLARE_UNSMOB(Music,music); #endif // MUSIC_HH diff --git a/lily/include/pitch.hh b/lily/include/pitch.hh index c88ed87ff0..c76b11182e 100644 --- a/lily/include/pitch.hh +++ b/lily/include/pitch.hh @@ -72,7 +72,7 @@ public: }; -Pitch* unsmob_pitch (SCM); +DECLARE_UNSMOB(Pitch,pitch); #include "compare.hh" INSTANTIATE_COMPARE (Pitch, Pitch::compare); diff --git a/lily/include/score.hh b/lily/include/score.hh index 78dc4ccabd..af1e3caccb 100644 --- a/lily/include/score.hh +++ b/lily/include/score.hh @@ -37,5 +37,5 @@ public: private: void run_translator (Music_output_def*); }; -Score * unsmob_score (SCM); +DECLARE_UNSMOB(Score,score); #endif diff --git a/lily/include/smobs.hh b/lily/include/smobs.hh index a295473616..437235c9ea 100644 --- a/lily/include/smobs.hh +++ b/lily/include/smobs.hh @@ -110,7 +110,12 @@ private:\ static int print_smob (SCM s, SCM p, scm_print_state*); \ public: \ static SCM equal_p (SCM a, SCM b);\ - static CL * unsmob (SCM);\ + static CL * unsmob (SCM s){\ + if (SCM_NIMP (s) && SCM_CELL_TYPE (s) == smob_tag_) \ + return (CL*) SCM_CELL_WORD_1 (s); \ + else \ + return 0; \ +} \ static SCM smob_p (SCM);\ static void init_smobs (); \ private: @@ -128,6 +133,14 @@ public: \ SCM self_scm () const { return self_scm_; } \ private: +#define DECLARE_UNSMOB(CL,name) \ +inline CL * \ +unsmob_ ## name (SCM s) \ +{ \ +return CL::unsmob (s); \ +} + + #endif /* SMOBS_HH */ diff --git a/lily/include/translator-def.hh b/lily/include/translator-def.hh index 77082e268d..fd6d42fd77 100644 --- a/lily/include/translator-def.hh +++ b/lily/include/translator-def.hh @@ -64,7 +64,7 @@ private: }; -Translator_def* unsmob_translator_def (SCM); +DECLARE_UNSMOB(Translator_def,translator_def); #endif /* TRANSLATOR_DEF_HH */ diff --git a/lily/include/translator.hh b/lily/include/translator.hh index 9877495be1..6c1ff11327 100644 --- a/lily/include/translator.hh +++ b/lily/include/translator.hh @@ -142,5 +142,5 @@ extern Dictionary *global_translator_dict_p; void add_translator (Translator*trans_p); Translator*get_translator_l (String s); -Translator *unsmob_translator (SCM); +DECLARE_UNSMOB(Translator,translator); #endif // TRANSLATOR_HH diff --git a/lily/molecule.cc b/lily/molecule.cc index f1aedc2295..c4c46411db 100644 --- a/lily/molecule.cc +++ b/lily/molecule.cc @@ -268,4 +268,4 @@ Molecule::mark_smob (SCM s) IMPLEMENT_TYPE_P (Molecule, "molecule?"); IMPLEMENT_DEFAULT_EQUAL_P (Molecule); -IMPLEMENT_UNSMOB (Molecule, molecule); + diff --git a/lily/moment.cc b/lily/moment.cc index 91eea12f12..5b1f1d9027 100644 --- a/lily/moment.cc +++ b/lily/moment.cc @@ -13,7 +13,7 @@ #include "warn.hh" #include "ly-smobs.icc" -IMPLEMENT_UNSMOB (Moment,moment); + IMPLEMENT_SIMPLE_SMOBS (Moment); IMPLEMENT_TYPE_P (Moment, "moment?"); diff --git a/lily/music-output-def.cc b/lily/music-output-def.cc index 308b025773..df2c404764 100644 --- a/lily/music-output-def.cc +++ b/lily/music-output-def.cc @@ -66,7 +66,7 @@ Music_output_def::Music_output_def (Music_output_def const &s) IMPLEMENT_SMOBS (Music_output_def); -IMPLEMENT_UNSMOB (Music_output_def,music_output_def); + IMPLEMENT_DEFAULT_EQUAL_P (Music_output_def); SCM diff --git a/lily/music.cc b/lily/music.cc index c9955845da..d3f5cdb4a8 100644 --- a/lily/music.cc +++ b/lily/music.cc @@ -135,7 +135,7 @@ Music::transpose (Pitch) } IMPLEMENT_TYPE_P (Music, "music?"); -IMPLEMENT_UNSMOB (Music,music); + IMPLEMENT_SMOBS (Music); IMPLEMENT_DEFAULT_EQUAL_P (Music); diff --git a/lily/pitch.cc b/lily/pitch.cc index 54d876cfa7..46013523fd 100644 --- a/lily/pitch.cc +++ b/lily/pitch.cc @@ -240,7 +240,7 @@ pitch_transpose (SCM p, SCM delta) IMPLEMENT_TYPE_P (Pitch, "pitch?"); -IMPLEMENT_UNSMOB (Pitch, pitch); + SCM Pitch::mark_smob (SCM) { diff --git a/lily/scm-hash.cc b/lily/scm-hash.cc index 7eeb67188b..5a4d27018a 100644 --- a/lily/scm-hash.cc +++ b/lily/scm-hash.cc @@ -153,7 +153,7 @@ Scheme_hash_table::to_alist () const -IMPLEMENT_UNSMOB (Scheme_hash_table,scheme_hash); + IMPLEMENT_SMOBS (Scheme_hash_table); IMPLEMENT_DEFAULT_EQUAL_P (Scheme_hash_table); diff --git a/lily/score.cc b/lily/score.cc index 9cc2f6d0c6..9b8d379999 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -166,7 +166,7 @@ Score::add_output (Music_output_def *pap_p) IMPLEMENT_SMOBS (Score); IMPLEMENT_DEFAULT_EQUAL_P (Score); -IMPLEMENT_UNSMOB (Score, score); + SCM Score::mark_smob (SCM s) diff --git a/lily/syllable-group.cc b/lily/syllable-group.cc index 119acd03df..3106026868 100644 --- a/lily/syllable-group.cc +++ b/lily/syllable-group.cc @@ -259,7 +259,7 @@ Syllable_group::print_smob (SCM, SCM port, scm_print_state *) return 1; } -IMPLEMENT_UNSMOB (Syllable_group, voice_entry); + IMPLEMENT_SIMPLE_SMOBS (Syllable_group); IMPLEMENT_DEFAULT_EQUAL_P (Syllable_group); diff --git a/lily/translator-def.cc b/lily/translator-def.cc index 1d1f65aeb5..200e0513cc 100644 --- a/lily/translator-def.cc +++ b/lily/translator-def.cc @@ -208,7 +208,7 @@ Translator_def::path_to_acceptable_translator (SCM type_str, Music_output_def* o return best_result; } -IMPLEMENT_UNSMOB (Translator_def,translator_def); + IMPLEMENT_SMOBS (Translator_def); IMPLEMENT_DEFAULT_EQUAL_P (Translator_def); diff --git a/lily/translator.cc b/lily/translator.cc index fd9f367df6..ef5f4b100a 100644 --- a/lily/translator.cc +++ b/lily/translator.cc @@ -207,6 +207,6 @@ Translator::static_translator_description ()const return SCM_EOL; } -IMPLEMENT_UNSMOB (Translator, translator); + IMPLEMENT_SMOBS (Translator); IMPLEMENT_DEFAULT_EQUAL_P (Translator); diff --git a/scripts/midi2ly.py b/scripts/midi2ly.py index 0c3b42ae05..23ca1264f8 100644 --- a/scripts/midi2ly.py +++ b/scripts/midi2ly.py @@ -7,6 +7,9 @@ import string LINE_BELL = 60 scale_steps = [0,2,4,5,7,9,11] +whole_clocks = 1536 +quart_clocks = 0 + def split_track (track): chs = {} for i in range(16): @@ -35,15 +38,15 @@ def split_track (track): class Note: - def __init__ (self, duration, pitch, velocity): + def __init__ (self, clocks, pitch, velocity): self.velocity = velocity self.pitch = pitch - self.duration = duration + self.clocks = clocks - def duration_compare (a, b): - if a.duration < b.duration: + def clocks_compare (a, b): + if a.clocks < b.clocks: return -1 - elif a.duration > b.duration: + elif a.clocks > b.clocks: return 1 else: return 0 @@ -53,40 +56,54 @@ class Note: class Time: def __init__ (self, t, num, den): - self.duration = t + self.skip = t self.num = num self.den = den + self.clocks = 0 def dump (self): - return dump_skip (self.duration) + '\\time %d/%d ' % (self.num, self.den) + s = '' + if self.skip: + s = dump_skip (self.skip) + s = s + '\n ' + return s + '\\time %d/%d ' % (self.num, self.den) + '\n ' class Key: key_sharps = ('c', 'g', 'd', 'a', 'e', 'b', 'fis') key_flats = ('BUG', 'f', 'bes', 'es', 'as', 'des', 'ges') def __init__ (self, t, sharps, flats, minor): - self.duration = t + self.skip = t self.flats = flats self.sharps = sharps self.minor = minor + self.clocks = 0 def dump (self): + s = '' + if self.skip: + s = dump_skip (self.skip) + s = s + '\n ' if self.sharps and self.flats: s = '\\keysignature %s ' % 'TODO' elif self.sharps: - s = '\\notes\\key %s \major' % key_sharps[self.sharps] + s = '\\notes\\key %s \major' % self.key_sharps[self.sharps] elif self.flats: - s = '\\notes\\key %s \major' % key_flats[self.flats] - return dump_skip (self.duration) + s + s = '\\notes\\key %s \major' % self.key_flats[self.flats] + return s + '\n ' class Text: - def __init__ (self, text): + def __init__ (self, t, text): + self.skip = t self.text = text - self.duration = 0 - + self.clocks = 0 + def dump (self): - return dump_text (self) + s = '' + if self.skip: + s = dump_skip (self.skip) + return s + dump_text (self) def notes_on_channel (channel): pitches = {} @@ -103,7 +120,7 @@ def notes_on_channel (channel): (lt, vel) = pitches[e[1][1]] del pitches[e[1][1]] - nch.append ((t, Note (t-lt, e[1][1], vel))) + nch.append ((lt, Note (t-lt, e[1][1], vel))) except KeyError: pass @@ -121,7 +138,7 @@ def notes_on_channel (channel): flats = 256 - accidentals nch.append ((t, Key (t, sharps, flats, minor))) elif e[1][1] == midi.TEXT_EVENT: - nch.append ((t, Text (e[1][2]))) + nch.append ((t, Text (t, e[1][2]))) else: sys.stderr.write ("SKIP: %s\n" % `e`) pass @@ -140,11 +157,11 @@ def unthread_notes (channel): todo = [] for e in channel: t = e[0] - if e[1].__class__ == Note and ((t == start_busy_t and e[1].duration + t == end_busy_t) \ + if e[1].__class__ == Note and ((t == start_busy_t and e[1].clocks + t == end_busy_t) \ or t >= end_busy_t): thread.append (e) start_busy_t = t - end_busy_t = t + e[1].duration + end_busy_t = t + e[1].clocks elif e[1].__class__ == Time or e[1].__class__ == Key or e[1].__class__ == Text: thread.append (e) else: @@ -164,20 +181,18 @@ def gcd (a,b): b = c return a -def dump_skip (dt): - return 's' + dump_duration (dt) - -def dump_duration (dur): - g = gcd (dur, 384) - s = '4' - (p,q) = (dur / g, 384 / g) - if (p == 1 and q == 1) : - pass +def dump_skip (clocks): + return 's' + dump_duration (clocks) + ' ' + +def dump_duration (clocks): + g = gcd (clocks, whole_clocks) + (d, n) = (whole_clocks/ g, clocks / g) + if n == 1: + s = '%d' % d + elif n == 3 and d != 1: + s = '%d.' % (d / 2) else: - if p <> 1: - s = s + '*%d'% p - if q <> 1: - s = s + '*%d'% q + s = '%d*%d' % (d, n) return s def dump_note (note): @@ -196,7 +211,7 @@ def dump_note (note): if scale_steps[i] <> step: str = str + 'is' - return ' %s' % str + dump_duration (note.duration) + return str + dump_duration (note.clocks) + ' ' def dump (self): return self.dump () @@ -245,7 +260,7 @@ def dump_channel (thread): lines[-1] = lines[-1] + dump_chord (ch[1]) - last_t = t + ch[1][0].duration + last_t = t + ch[1][0].clocks return string.join (lines, '\n ') + '\n' @@ -286,9 +301,13 @@ def dump_track (channels, n): def convert_midi (f): + global whole_clocks, quart_clocks + str = open (f).read () midi_dump = midi.parse (str) + whole_clocks = midi_dump[0][1] + quart_clocks = whole_clocks / 4 tracks = [] for t in midi_dump[1]: -- 2.39.5