]> git.donarmstrong.com Git - lilypond.git/commitdiff
Midi2ly: add quantize tests and voices fixlet.
authorJan Nieuwenhuizen <janneke@gnu.org>
Sat, 12 Mar 2011 22:16:23 +0000 (23:16 +0100)
committerJan Nieuwenhuizen <janneke@gnu.org>
Sat, 12 Mar 2011 22:16:23 +0000 (23:16 +0100)
input/regression/midi/quantize-duration.ly [new file with mode: 0644]
input/regression/midi/quantize-start.ly [new file with mode: 0644]
scripts/midi2ly.py

diff --git a/input/regression/midi/quantize-duration.ly b/input/regression/midi/quantize-duration.ly
new file mode 100644 (file)
index 0000000..1994eeb
--- /dev/null
@@ -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 (file)
index 0000000..089f5f1
--- /dev/null
@@ -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 {}
+}
index f0c64358c4961cb92e6815592cb18f5fad3936b8..9f2b7f01cb35532208220d5c4ff19acfe66a7b56 100644 (file)
@@ -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