lydown 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66935404398a57aa09da31ebddd911edae7227fe
4
- data.tar.gz: 6bc6875c3b2e2187140a91bb586b53411aeb57c3
3
+ metadata.gz: 5f65c145556a28db3b86c183d1f12460e903c4fa
4
+ data.tar.gz: 2c7faca659a582e802793be8c84551efdb0e863d
5
5
  SHA512:
6
- metadata.gz: 28dcdb1e4501356d371f3ff217af806f966a37fe24611fe7f33426ec264d80b197fc609441fef6953b3929d9239436289950e05983d0bbf15f8fc58770663392
7
- data.tar.gz: 36a98eb309977703065fb6feb0dc5284b2f78d7b241f40606f0098087980e70415258d9df13d30b06854ac40b92a93fec84bdad93cb6fe9acaea565d3d8e76c0
6
+ metadata.gz: 138a326275fd7b015c991439ef18c9533d4928d04fcfe9700a8a102712250d2e0e1839a844ea31cb0fe96cbe7c3caa56a9ec0f4c02759f0550d41976f5738ba0
7
+ data.tar.gz: 3c8d435a1971f739c50b3b9bd8d4987a7f928ab418583fa1a8c0125e725deebc5f38420bc261902dd53dd2ab9767a0430f2be44d3f3a89807fa78f683fc5e832
@@ -55,7 +55,10 @@ grammar Lydown
55
55
  # '.|') <Barline>
56
56
  end
57
57
  rule duration
58
- duration_value / duration_macro
58
+ tuplet_value / duration_value / duration_macro
59
+ end
60
+ rule tuplet_value
61
+ number '%' (number '/' number)? <TupletValue>
59
62
  end
60
63
  rule duration_value
61
64
  number dots* multiplier? <DurationValue>
@@ -113,7 +116,7 @@ grammar Lydown
113
116
  [s] multiplier* <Silence>
114
117
  end
115
118
  rule note_head
116
- [a-g] accidental* <Note::Head>
119
+ [a-g] octave* accidental* <Note::Head>
117
120
  end
118
121
  rule accidental
119
122
  [\+\-]+
@@ -58,6 +58,25 @@ module Lydown::Parsing
58
58
  end
59
59
  end
60
60
 
61
+ module TupletValue
62
+ def to_stream(stream)
63
+ if text_value =~ /^(\d+)%((\d+)\/(\d+))?$/
64
+ value, fraction, group_length = $1, $2, $4
65
+ unless fraction
66
+ fraction = '3/2'
67
+ group_length = '2'
68
+ end
69
+
70
+ stream << {
71
+ type: :tuplet_duration,
72
+ value: value,
73
+ fraction: fraction,
74
+ group_length: group_length
75
+ }
76
+ end
77
+ end
78
+ end
79
+
61
80
  module Note
62
81
  include Root
63
82
 
@@ -69,7 +88,10 @@ module Lydown::Parsing
69
88
 
70
89
  module Head
71
90
  def to_stream(note)
72
- note[:head] = text_value
91
+ # remove octave marks from note head (this is only in case the order
92
+ # accidental-octave was reversed)
93
+ head = text_value.gsub(/[',]+/) {|m| note[:octave] = m; ''}
94
+ note[:head] = head
73
95
  end
74
96
  end
75
97
 
@@ -169,7 +169,7 @@ module Lydown::Rendering
169
169
  @work['process/duration_macro'] = nil
170
170
 
171
171
  code = LydownParser.parse(@work['process/macro_group'])
172
- @work.process(code)
172
+ @work.process(code, no_reset: true)
173
173
 
174
174
  # restore macro
175
175
  @work['process/duration_macro'] = macro
@@ -185,15 +185,42 @@ module Lydown::Rendering
185
185
 
186
186
  class Duration < Base
187
187
  def translate
188
+ # close tuplet braces
189
+ if @work['process/tuplet_mode']
190
+ TupletDuration.emit_tuplet_end(@work)
191
+ @work['process/tuplet_mode'] = nil
192
+ end
193
+
188
194
  value = @event[:value].sub(/^[0-9]+/) {|m| LILYPOND_DURATIONS[m] || m}
189
195
 
190
196
  if next_event && next_event[:type] == :stand_alone_figures
191
197
  @work['process/figures_duration_value'] = value
192
198
  else
193
199
  @work['process/duration_values'] = [value]
200
+ @work['process/tuplet_mode'] = nil
194
201
  @work['process/duration_macro'] = nil unless @work['process/macro_group']
195
202
  end
196
203
  end
204
+
205
+ end
206
+
207
+ class TupletDuration < Base
208
+ def self.emit_tuplet_end(work)
209
+ work.emit(:music, '} ')
210
+ end
211
+
212
+ def translate
213
+ if next_event && next_event[:type] == :stand_alone_figures
214
+ @work['process/figures_duration_value'] = "#{@event[:value]}*#{@event[:fraction]}"
215
+ else
216
+ @work['process/duration_values'] = [@event[:value]]
217
+ @work['process/last_value'] = nil
218
+ @work['process/tuplet_mode'] = true
219
+
220
+ group_value = @event[:value].to_i / @event[:group_length].to_i
221
+ @work.emit(:music, "\\tuplet #{@event[:fraction]} #{group_value} { ")
222
+ end
223
+ end
197
224
  end
198
225
 
199
226
  class Note < Base
@@ -1,3 +1,3 @@
1
1
  module Lydown
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/lydown/work.rb CHANGED
@@ -34,16 +34,16 @@ module Lydown
34
34
  @context[:beaming] = nil
35
35
  @context[:end_barline] = nil
36
36
  @context[:part] = nil
37
- @context['process/duration_values'] = ['4']
38
- @context['process/running_values'] = []
39
- @context['process/last_value'] = nil
40
- @context['process/last_figures_value'] = nil
41
- when :part
42
- @context['process/duration_values'] = ['4']
43
- @context['process/running_values'] = []
44
- @context['process/last_value'] = nil
45
- @context['process/last_figures_value'] = nil
46
37
  end
38
+ if @context['process/tuplet_mode']
39
+ Lydown::Rendering::TupletDuration.emit_tuplet_end(self)
40
+ end
41
+
42
+ # reset processing variables
43
+ @context['process'] = {
44
+ 'duration_values' => ['4'],
45
+ 'running_values' => []
46
+ }
47
47
  end
48
48
 
49
49
  # Used to bind to instance when rendering templates
@@ -54,7 +54,7 @@ module Lydown
54
54
  end
55
55
 
56
56
  # translate a lydown stream into lilypond
57
- def process(lydown_stream)
57
+ def process(lydown_stream, opts = {})
58
58
  lydown_stream.each_with_index do |e, idx|
59
59
  if e[:type]
60
60
  Lydown::Rendering.translate(self, e, lydown_stream, idx)
@@ -62,6 +62,7 @@ module Lydown
62
62
  raise LydownError, "Invalid lydown stream event: #{e.inspect}"
63
63
  end
64
64
  end
65
+ reset_context(:part) unless opts[:no_reset]
65
66
  end
66
67
 
67
68
  def emit(stream_type, *content)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lydown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-21 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: treetop
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
- description: 'Lydown '
27
+ description: Lydown is a language and tool for music notation
28
28
  email: ciconia@gmail.com
29
29
  executables:
30
30
  - lydown