From 55ed3dba5094da3fbab324a028174f2b28d74c30 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 12 Mar 2011 23:16:23 +0100 Subject: [PATCH] Midi2ly: add quantize tests and voices fixlet. --- input/regression/midi/quantize-duration.ly | 57 ++++++++++++++++++++++ input/regression/midi/quantize-start.ly | 57 ++++++++++++++++++++++ scripts/midi2ly.py | 10 +++- 3 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 input/regression/midi/quantize-duration.ly create mode 100644 input/regression/midi/quantize-start.ly diff --git a/input/regression/midi/quantize-duration.ly b/input/regression/midi/quantize-duration.ly new file mode 100644 index 0000000000..1994eeb547 --- /dev/null +++ b/input/regression/midi/quantize-duration.ly @@ -0,0 +1,57 @@ +% Lily was here -- automatically converted by ../../../scripts/midi2ly.py from out-www/voice-2.midi +\version "2.13.53" + +\layout { + \context { + \Voice + \remove "Note_heads_engraver" + \consists "Completion_heads_engraver" + \remove "Rest_engraver" + \consists "Completion_rest_engraver" + } +} + +% included from ./out-www/voice-2.header +\header { +texidoc="midi2ly --duration-quant quantizes durations of notes" +options="--duration-quant=4" +} +% end + +trackAchannelA = { + + % [SEQUENCE_TRACK_NAME] control track + + % [TEXT_EVENT] creator: + + % [TEXT_EVENT] GNU LilyPond 2.13.54 + + \time 4/4 + + \tempo 4 = 60 + +} + +trackA = << + \context Voice = voiceA \trackAchannelA +>> + + +trackBchannelA = \relative c { + r4*1/8 c4*7/8 + c4*7/8 r4*1/8 +} + +trackB = << + \context Voice = voiceA \trackBchannelA +>> + + +\score { + << + %\set Score.midiChannelMapping = #'voice + \context Staff=trackB \trackB + >> + \layout {} + \midi {} +} diff --git a/input/regression/midi/quantize-start.ly b/input/regression/midi/quantize-start.ly new file mode 100644 index 0000000000..089f5f1c78 --- /dev/null +++ b/input/regression/midi/quantize-start.ly @@ -0,0 +1,57 @@ +% Lily was here -- automatically converted by ../../../scripts/midi2ly.py from out-www/voice-2.midi +\version "2.13.53" + +\layout { + \context { + \Voice + \remove "Note_heads_engraver" + \consists "Completion_heads_engraver" + \remove "Rest_engraver" + \consists "Completion_rest_engraver" + } +} + +% included from ./out-www/voice-2.header +\header { +texidoc="midi2ly --start-quant quantizes start of notes" +options="--start-quant=4" +} +% end + +trackAchannelA = { + + % [SEQUENCE_TRACK_NAME] control track + + % [TEXT_EVENT] creator: + + % [TEXT_EVENT] GNU LilyPond 2.13.54 + + \time 4/4 + + \tempo 4 = 60 + +} + +trackA = << + \context Voice = voiceA \trackAchannelA +>> + + +trackBchannelA = \relative c { + r4*1/8 c4*7/8 + c4*7/8 r4*1/8 +} + +trackB = << + \context Voice = voiceA \trackBchannelA +>> + + +\score { + << + \set Score.midiChannelMapping = #'voice + \context Staff=trackB \trackB + >> + \layout {} + \midi {} +} diff --git a/scripts/midi2ly.py b/scripts/midi2ly.py index f0c64358c4..9f2b7f01cb 100644 --- a/scripts/midi2ly.py +++ b/scripts/midi2ly.py @@ -497,7 +497,6 @@ def events_on_channel (channel): if start_quant_clocks: t = quantise_clocks (t, start_quant_clocks) - if (e[1][0] == midi.NOTE_OFF or (e[1][0] == midi.NOTE_ON and e[1][2] == 0)): debug ('%d: NOTE OFF: %s' % (t, e[1][1])) @@ -764,10 +763,14 @@ def get_voice_name (i, zero_too_p=False): return 'voice' + number2ascii (i) return '' +def lst_append (lst, x): + lst.append (x) + return lst + def get_voice_layout (average_pitch): d = {} for i in range (len (average_pitch)): - d[average_pitch[i]] = i + d[average_pitch[i]] = lst_append (d.get (average_pitch[i], []), i) s = list (reversed (sorted (average_pitch))) non_empty = len (filter (lambda x: x, s)) names = ['One', 'Two'] @@ -777,6 +780,9 @@ def get_voice_layout (average_pitch): for i, n in zip (s, names): if i: v = d[i] + if type (v) == list: + d[i] = v[1:] + v = v[0] layout[v] = n return layout -- 2.39.5