jmtk 0.0.3.3-java → 0.4-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +15 -0
  2. data/DEVELOPMENT_NOTES.md +20 -0
  3. data/INTRO.md +63 -31
  4. data/README.md +9 -3
  5. data/Rakefile +42 -42
  6. data/bin/jmtk +75 -32
  7. data/bin/mtk +75 -32
  8. data/examples/drum_pattern.rb +2 -2
  9. data/examples/dynamic_pattern.rb +1 -1
  10. data/examples/helpers/output_selector.rb +71 -0
  11. data/examples/notation.rb +5 -1
  12. data/examples/tone_row_melody.rb +1 -1
  13. data/lib/mtk.rb +1 -0
  14. data/lib/mtk/core/duration.rb +18 -3
  15. data/lib/mtk/core/intensity.rb +5 -3
  16. data/lib/mtk/core/interval.rb +21 -14
  17. data/lib/mtk/core/pitch.rb +2 -0
  18. data/lib/mtk/core/pitch_class.rb +6 -3
  19. data/lib/mtk/events/event.rb +2 -1
  20. data/lib/mtk/events/note.rb +1 -1
  21. data/lib/mtk/events/parameter.rb +1 -0
  22. data/lib/mtk/events/rest.rb +85 -0
  23. data/lib/mtk/events/timeline.rb +6 -2
  24. data/lib/mtk/io/jsound_input.rb +9 -3
  25. data/lib/mtk/io/midi_file.rb +38 -2
  26. data/lib/mtk/io/midi_input.rb +1 -1
  27. data/lib/mtk/io/midi_output.rb +95 -4
  28. data/lib/mtk/io/unimidi_input.rb +7 -3
  29. data/lib/mtk/lang/durations.rb +31 -26
  30. data/lib/mtk/lang/intensities.rb +29 -30
  31. data/lib/mtk/lang/intervals.rb +108 -41
  32. data/lib/mtk/lang/mtk_grammar.citrus +14 -4
  33. data/lib/mtk/lang/parser.rb +10 -5
  34. data/lib/mtk/lang/pitch_classes.rb +45 -17
  35. data/lib/mtk/lang/pitches.rb +169 -32
  36. data/lib/mtk/lang/tutorial.rb +279 -0
  37. data/lib/mtk/lang/tutorial_lesson.rb +87 -0
  38. data/lib/mtk/sequencers/event_builder.rb +29 -8
  39. data/spec/mtk/core/duration_spec.rb +14 -1
  40. data/spec/mtk/core/intensity_spec.rb +1 -1
  41. data/spec/mtk/events/event_spec.rb +10 -16
  42. data/spec/mtk/events/note_spec.rb +3 -3
  43. data/spec/mtk/events/rest_spec.rb +184 -0
  44. data/spec/mtk/events/timeline_spec.rb +5 -1
  45. data/spec/mtk/io/midi_file_spec.rb +13 -2
  46. data/spec/mtk/io/midi_output_spec.rb +42 -9
  47. data/spec/mtk/lang/durations_spec.rb +5 -5
  48. data/spec/mtk/lang/intensities_spec.rb +5 -5
  49. data/spec/mtk/lang/intervals_spec.rb +139 -13
  50. data/spec/mtk/lang/parser_spec.rb +65 -25
  51. data/spec/mtk/lang/pitch_classes_spec.rb +0 -11
  52. data/spec/mtk/lang/pitches_spec.rb +0 -15
  53. data/spec/mtk/patterns/chain_spec.rb +7 -7
  54. data/spec/mtk/patterns/for_each_spec.rb +2 -2
  55. data/spec/mtk/sequencers/event_builder_spec.rb +49 -17
  56. metadata +12 -22
@@ -3,57 +3,56 @@ module MTK
3
3
 
4
4
  # Defines intensity constants using standard dynamic symbols.
5
5
  #
6
- # These can be thought of like constants, but in order to distinguish 'f' (forte) from the {PitchClass} 'F'
7
- # it was necessary to use lower-case names and therefore define them as "pseudo constant" methods.
8
- # The methods are available either through the module (MTK::Intensities::f) or via mixin (include MTK::Intensities; f)
6
+ # These can be thought of like constants, but in order to support the lower case names,
7
+ # it was necessary to define them as "pseudo constant" methods.
8
+ # Like constants, these methods are available either through the module (MTK::Lang::Intensities::f) or
9
+ # via mixin (include MTK::Lang::Intensities; f). They are listed under the "Instance Attribute Summary" of this page.
9
10
  #
10
11
  # These values are intensities in the range 0.125 - 1.0 (in increments of 1/8), so they can be easily scaled (unlike MIDI velocities).
11
12
  #
12
- # It is also possible to retrieve values in increments of 1/24 by using the '+' and '-' suffix when looking
13
- # up values via the {.[]} method.
14
- #
15
13
  # @note Including this module shadows Ruby's built-in p() method.
16
- # If you include this module, you can access the built-in p() method via Kernel.p()
14
+ # If you include this module, you can access the built-in p() method via Kernel.p()
15
+ # Also be aware you might shadow existing variable names, like f.
17
16
  #
18
- # @see Note
17
+ # @see Core::Intensity
18
+ # @see Events::Note
19
19
  module Intensities
20
20
  extend MTK::Lang::PseudoConstants
21
21
 
22
- # NOTE: the yard doc macros here only fill in [$2] with the actual value when generating docs under Ruby 1.9+
22
+ # @private
23
+ # @!macro [attach] define_intensity
24
+ # $3: $4% intensity
25
+ # @!attribute [r]
26
+ # @return [MTK::Core::Interval] intensity of $4%
27
+ def self.define_intensity name, value, description, percentage_intensity
28
+ define_constant name, value
29
+ end
30
+
23
31
 
24
- # pianississimo
25
- # @macro [attach] intensities.define_constant
26
- # @attribute [r]
27
- # @return [$2] intensity value for $1
28
- define_constant 'ppp', MTK::Core::Intensity[0.125]
32
+ define_intensity 'ppp', MTK::Core::Intensity[0.125], 'pianississimo', '12.5'
29
33
 
30
- # pianissimo
31
- define_constant 'pp', MTK::Core::Intensity[0.25]
34
+ define_intensity 'pp', MTK::Core::Intensity[0.25], 'pianissimo', 25
32
35
 
33
- # piano
34
36
  # @note Including this module shadows Ruby's built-in p() method.
35
37
  # If you include this module, you can access the built-in p() method via Kernel.p()
36
- define_constant 'p', MTK::Core::Intensity[0.375]
38
+ define_intensity 'p', MTK::Core::Intensity[0.375], 'piano', '37.5'
39
+
40
+ define_intensity 'mp', MTK::Core::Intensity[0.5], 'mezzo-piano', 50
37
41
 
38
- # mezzo-piano
39
- define_constant 'mp', MTK::Core::Intensity[0.5]
42
+ define_intensity 'mf', MTK::Core::Intensity[0.625], 'mezzo-forte', '62.5'
40
43
 
41
- # mezzo-forte
42
- define_constant 'mf', MTK::Core::Intensity[0.625]
44
+ define_intensity 'f', MTK::Core::Intensity[0.75], 'forte', 75
43
45
 
44
- # forte
45
- define_constant 'o', MTK::Core::Intensity[0.75]
46
+ define_intensity 'ff', MTK::Core::Intensity[0.875], 'fortissimo', '87.5'
46
47
 
47
- # fortissimo
48
- define_constant 'ff', MTK::Core::Intensity[0.875]
48
+ define_intensity 'fff', MTK::Core::Intensity[1.0], 'fortississimo', 100
49
49
 
50
- # fortississimo
51
- define_constant 'fff', MTK::Core::Intensity[1.0]
52
50
 
53
- # The values of all "psuedo constants" defined in this module
54
- INTENSITIES = [ppp, pp, p, mp, mf, o, ff, fff].freeze
51
+ # All "psuedo constants" defined in this module
52
+ INTENSITIES = [ppp, pp, p, mp, mf, f, ff, fff].freeze
55
53
 
56
54
  # The names of all "psuedo constants" defined in this module
55
+ # @see MTK::Core::Intensity::NAMES
57
56
  INTENSITY_NAMES = MTK::Core::Intensity::NAMES
58
57
 
59
58
  end
@@ -1,72 +1,139 @@
1
1
  module MTK
2
2
  module Lang
3
3
 
4
- # Defines a constant for intervals up to an octave using diatonic naming conventions (see http://en.wikipedia.org/wiki/Interval_(music)#Main_intervals)
4
+ # Defines a constant for {Core::Interval}s up to an octave using diatonic naming conventions
5
5
  #
6
6
  # Naming conventions
7
7
  # P#: perfect interval
8
8
  # M#: major interval
9
9
  # m#: minor interval
10
- # TT: tritone (AKA augmented 4th or diminished 5th)
10
+ # TT: tritone
11
+ # a#: augmented interval
12
+ # d#: diminished interval
11
13
  #
12
- # These can be thought of like constants, but in order to succinctly distinguish 'm2' (minor) from 'M2' (major),
13
- # it was necessary to use lower-case names for some of the values and therefore define them as "pseudo constant" methods.
14
- # The methods are available either through the module (MTK::Core::Intervals::m2) or via mixin (include MTK::Core::Intervals; m2)
14
+ # These can be thought of like constants, but in order to support the lower case names,
15
+ # it was necessary to define them as "pseudo constant" methods.
16
+ # Like constants, these methods are available either through the module (MTK::Lang::Intervals::m2) or
17
+ # via mixin (include MTK::Lang::Intervals; m2). They are listed under the "Instance Attribute Summary" of this page.
18
+ #
19
+ # @see Core::Interval
20
+ # @see http://en.wikipedia.org/wiki/Interval_(music)#Main_intervals
15
21
  module Intervals
16
22
  extend MTK::Lang::PseudoConstants
17
23
 
18
- # NOTE: the yard doc macros here only fill in [$2] with the actual value when generating docs under Ruby 1.9+
24
+ # @private
25
+ # @!macro [attach] define_interval
26
+ # $3: $4 semitones
27
+ # @!attribute [r]
28
+ # @return [MTK::Core::Interval] interval of $4 semitones
29
+ def self.define_interval name, value, description, semitones
30
+ define_constant name, value
31
+ end
32
+
33
+
34
+ # @see #d2
35
+ define_interval 'P1', MTK::Core::Interval[0], 'perfect unison', 0
36
+
37
+ # @see #P1
38
+ define_interval 'd2', MTK::Core::Interval[0], 'diminished second', 0
39
+
40
+
41
+ # @see #a1
42
+ define_interval 'm2', MTK::Core::Interval[1], 'minor second', 1
43
+
44
+ # @see #m2
45
+ define_interval 'a1', MTK::Core::Interval[1], 'augmented unison', 1
46
+
47
+
48
+ # @see #d3
49
+ define_interval 'M2', MTK::Core::Interval[2], 'major second', 2
50
+
51
+ # @see #M2
52
+ define_interval 'd3', MTK::Core::Interval[2], 'diminished third', 2
53
+
54
+
55
+ # @see #a2
56
+ define_interval 'm3', MTK::Core::Interval[3], 'minor third', 3
57
+
58
+ # @see #m3
59
+ define_interval 'a2', MTK::Core::Interval[3], 'augmented second', 3
60
+
61
+
62
+ # @see #d4
63
+ define_interval 'M3', MTK::Core::Interval[4], 'major third', 4
64
+
65
+ # @see #M3
66
+ define_interval 'd4', MTK::Core::Interval[4], 'diminished fourth', 4
67
+
68
+
69
+ # @see #a3
70
+ define_interval 'P4', MTK::Core::Interval[5], 'perfect fourth', 5
71
+
72
+ # @see #P4
73
+ define_interval 'a3', MTK::Core::Interval[5], 'augmented third', 5
74
+
75
+
76
+ # @see #a4
77
+ # @see #d5
78
+ define_interval 'TT', MTK::Core::Interval[6], 'tritone', 6
79
+
80
+ # @see #TT
81
+ # @see #d5
82
+ define_interval 'a4', MTK::Core::Interval[6], 'augmented fourth', 6
83
+
84
+ # @see #TT
85
+ # @see #a4
86
+ define_interval 'd5', MTK::Core::Interval[6], 'diminished fifth', 6
87
+
88
+
89
+ # @see #d6
90
+ define_interval 'P5', MTK::Core::Interval[7], 'perfect fifth', 7
91
+
92
+ # @see #P5
93
+ define_interval 'd6', MTK::Core::Interval[7], 'diminished sixth', 7
94
+
95
+
96
+ # @see #a5
97
+ define_interval 'm6', MTK::Core::Interval[8], 'minor sixth', 8
98
+
99
+ # @see #m6
100
+ define_interval 'a5', MTK::Core::Interval[8], 'augmented fifth', 8
19
101
 
20
- # perfect unison
21
- # @macro [attach] interval.define_constant
22
- # @attribute [r]
23
- # @return [$2] number of semitones in the interval $1
24
- define_constant 'P1', MTK::Core::Interval[0]
25
102
 
26
- # minor second
27
- # @macro [attach] interval.define_constant
28
- # @attribute [r]
29
- # @return [$2] number of semitones in the interval $1
30
- define_constant 'm2', MTK::Core::Interval[1]
103
+ # @see #d7
104
+ define_interval 'M6', MTK::Core::Interval[9], 'major sixth', 9
31
105
 
32
- # major second
33
- define_constant 'M2', MTK::Core::Interval[2]
106
+ # @see #M6
107
+ define_interval 'd7', MTK::Core::Interval[9], 'diminished seventh', 9
34
108
 
35
- # minor third
36
- define_constant 'm3', MTK::Core::Interval[3]
37
109
 
38
- # major third
39
- define_constant 'M3', MTK::Core::Interval[4]
110
+ # @see #a6
111
+ define_interval 'm7', MTK::Core::Interval[10], 'minor seventh', 10
40
112
 
41
- # pefect fourth
42
- define_constant 'P4', MTK::Core::Interval[5]
113
+ # @see #m7
114
+ define_interval 'a6', MTK::Core::Interval[10], 'augmented sixth', 10
43
115
 
44
- # tritone (AKA augmented fourth or diminished fifth)
45
- define_constant 'TT', MTK::Core::Interval[6]
46
116
 
47
- # perfect fifth
48
- define_constant 'P5', MTK::Core::Interval[7]
117
+ # @see #d8
118
+ define_interval 'M7', MTK::Core::Interval[11], 'major seventh', 11
49
119
 
50
- # minor sixth
51
- define_constant 'm6', MTK::Core::Interval[8]
120
+ # @see #M7
121
+ define_interval 'd8', MTK::Core::Interval[11], 'diminished octave', 11
52
122
 
53
- # major sixth
54
- define_constant 'M6', MTK::Core::Interval[9]
55
123
 
56
- # minor seventh
57
- define_constant 'm7', MTK::Core::Interval[10]
124
+ # @see #a7
125
+ define_interval 'P8', MTK::Core::Interval[12], 'perfect octave', 12
58
126
 
59
- # major seventh
60
- define_constant 'M7', MTK::Core::Interval[11]
127
+ # @see #P8
128
+ define_interval 'a7', MTK::Core::Interval[12], 'augmented seventh', 12
61
129
 
62
- # pefect octave
63
- define_constant 'P8', MTK::Core::Interval[12]
64
130
 
65
- # The values of all "psuedo constants" defined in this module
66
- INTERVALS = [P1, m2, M2, m3, M3, P4, TT, P5, m6, M6, m7, M7, P8].freeze
131
+ # All "psuedo constants" defined in this module
132
+ INTERVALS = [P1, d2, m2, a1, M2, d3, m3, a2, M3, d4, P4, a3, TT, a4, d5, P5, d6, m6, a5, M6, d7, m7, a6, M7, d8, P8, a7].freeze
67
133
 
68
134
  # The names of all "psuedo constants" defined in this module
69
- INTERVAL_NAMES = MTK::Core::Interval::NAMES
135
+ # @see MTK::Core::Interval::NAMES_BY_VALUE
136
+ INTERVAL_NAMES = MTK::Core::Interval::ALL_NAMES
70
137
 
71
138
  end
72
139
  end
@@ -133,25 +133,35 @@ grammar MTK_Grammar
133
133
  end
134
134
 
135
135
  rule pitch_class
136
- ( [A-Ga-g] [#b]*2 ) {
136
+ ( diatonic_pitch_class accidental? ) {
137
137
  MTK::Core::PitchClass[to_s]
138
138
  }
139
139
  end
140
140
 
141
+ rule diatonic_pitch_class
142
+ ( [A-G] ) {
143
+ MTK::Core::PitchClass[to_s]
144
+ }
145
+ end
146
+
147
+ rule accidental
148
+ ('#'1*2 | 'b'1*2)
149
+ end
150
+
141
151
  rule interval
142
- ( [Pp] [1458] | ('maj'|'min'|[Mm]) [2367] | 'TT' | 'tt' ) {
152
+ ( 'P' [1458] | [Mm] [2367] | 'a' [1-7] | 'd' [2-8] | 'TT' ) {
143
153
  MTK::Core::Interval.from_s(to_s)
144
154
  }
145
155
  end
146
156
 
147
157
  rule intensity
148
- ( ('p'1*3 | 'mp' | 'mf' | 'o' | 'f'2*3) ('+'|'-')? ) {
158
+ ( ('p'1*3 | 'mp' | 'mf' | 'f'1*3) ('+'|'-')? ) {
149
159
  MTK::Core::Intensity.from_s(to_s)
150
160
  }
151
161
  end
152
162
 
153
163
  rule duration
154
- ( rest:'-'? multiplier:number? [whqisrx] ('.'|'t')* ) {
164
+ ( rest:'-'? multiplier:number? [whqesrx] ('.'|'t')* ) {
155
165
  MTK::Core::Duration.from_s(to_s)
156
166
  }
157
167
  end
@@ -12,15 +12,20 @@ Citrus.load File.join(File.dirname(__FILE__),'mtk_grammar')
12
12
  module MTK
13
13
  module Lang
14
14
 
15
- # Parser for the {file:lib/mtk/lang/mtk_grammar.citrus MTK grammar}
15
+ # Parser for the {file:lib/mtk/lang/mtk_grammar.citrus MTK syntax}
16
16
  class Parser
17
17
 
18
- def self.parse(syntax, root=:root, dump=false)
18
+ # Parse the given MTK syntax according to the {file:lib/mtk/lang/mtk_grammar.citrus grammar rules}
19
+ # @return [Sequencers::LegatoSequencer] by default
20
+ # @return [Core,Patterns,Sequencers] a core object, pattern or sequencer when an optional grammar rule
21
+ # is given. Depends on the rule.
22
+ # @raise [Citrus::ParseError] for invalid syntax
23
+ def self.parse(syntax, grammar_rule=:root, dump=false)
19
24
  syntax = syntax.to_s.strip
20
25
  return nil if syntax.empty?
21
- matcher = ::MTK_Grammar.parse(syntax, :root => root)
22
- puts matcher.dump if dump
23
- matcher.value
26
+ match = ::MTK_Grammar.parse(syntax, root: grammar_rule)
27
+ puts match.dump if dump
28
+ match.value
24
29
  end
25
30
 
26
31
  end
@@ -1,29 +1,57 @@
1
1
  module MTK
2
2
  module Lang
3
3
 
4
- # Defines a constant for each {PitchClass} in the Western chromatic scale.
4
+ # Defines a constant for each {Core::PitchClass} in the Western chromatic scale.
5
+ #
6
+ # Because '#' is not a valid identifier character in Ruby. All chromatic pitch classes are defined as
7
+ # the flat of a diatonic pitch class, for example Eb is a constant because D# is not a valid Ruby constant name.
8
+ #
9
+ # To help automate the documentation, the constants are listed under "Instance Attribute Summary" on this page.
10
+ #
11
+ # @see Core::PitchClass
12
+ #
5
13
  module PitchClasses
6
14
 
7
- # The values of all constants defined in this module
8
- PITCH_CLASSES = MTK::Core::PitchClass::PITCH_CLASSES
15
+ # @private
16
+ # @!macro [attach] define_pitch_class
17
+ # PitchClass $1 $3
18
+ # @!attribute [r]
19
+ # @return [MTK::Core::PitchClass] PitchClass $1 (value $2)
20
+ def self.define_pitch_class name, value, more_info=nil
21
+ const_set name, MTK::Core::PitchClass.from_name(name)
22
+ end
23
+
24
+ define_pitch_class 'C', 0
25
+
26
+ define_pitch_class 'Db', 1, '(also known as C#)'
27
+
28
+ define_pitch_class 'D', 2
29
+
30
+ define_pitch_class 'Eb', 3, '(also known as D#)'
31
+
32
+ define_pitch_class 'E', 4
33
+
34
+ define_pitch_class 'F', 5
35
+
36
+ define_pitch_class 'Gb', 6, '(also known as F#)'
37
+
38
+ define_pitch_class 'G', 7
39
+
40
+ define_pitch_class 'Ab', 8, '(also known as G#)'
41
+
42
+ define_pitch_class 'A', 9
43
+
44
+ define_pitch_class 'Bb', 10, '(also known as A#)'
45
+
46
+ define_pitch_class 'B', 11
47
+
48
+ # All constants defined in this module
49
+ PITCH_CLASSES = [C, Db, D, Eb, E, F, Gb, G, Ab, A, Bb, B].freeze
9
50
 
10
51
  # The names of all constants defined in this module
52
+ # @see MTK::Core::PitchClass::NAMES
11
53
  PITCH_CLASS_NAMES = MTK::Core::PitchClass::NAMES
12
54
 
13
- PITCH_CLASSES.each { |pc| const_set pc.name, pc }
14
-
15
- # Lookup the value of an pitch class constant by name.
16
- # @example lookup value of 'C'
17
- # MTK::Core::PitchClasses['C']
18
- # @see Groups::PitchClass.[]
19
- def self.[](name)
20
- begin
21
- const_get name
22
- rescue
23
- nil
24
- end
25
- end
26
-
27
55
  end
28
56
  end
29
57
  end
@@ -2,51 +2,188 @@ module MTK
2
2
  module Lang
3
3
 
4
4
  # Defines a constants for each {Core::Pitch} in the standard MIDI range using scientific pitch notation.
5
+ # The constants range from C-1 (MIDI value 0) to G9 (MIDI value)
5
6
  #
6
- # See http://en.wikipedia.org/wiki/Scientific_pitch_notation
7
+ # Because the character '#' cannot be used in the name of a constant,
8
+ # the "black key" pitches are all named as flats with 'b' (for example, Gb3 or Db4).
9
+ # And because the character '-' (minus) cannot be used in the name of a constant,
10
+ # the low pitches use '_' (underscore) in place of '-' (minus) (for example C_1).
7
11
  #
8
- # @note Because the character '#' cannot be used in the name of a constant,
9
- # the "black key" pitches are all named as flats with 'b' (for example, Gb3 or Cb4)
10
- # @note Because the character '-' (minus) cannot be used in the name of a constant,
11
- # the low pitches use '_' (underscore) in place of '-' (minus) (for example C_1).
12
- module Pitches
12
+ # To help automate the documentation, the constants are listed under "Instance Attribute Summary" on this page.
13
+ #
14
+ # @see Core::Pitch
15
+ # @see Events::Note
16
+ # @see http://en.wikipedia.org/wiki/Scientific_pitch_notation
17
+ module Pitches
18
+
19
+ # @private
20
+ # @!macro [attach] define_pitch
21
+ # Pitch $1 (MIDI pitch $2)
22
+ # @!attribute [r]
23
+ # @return [MTK::Core::Pitch] Pitch $1 (value $2)
24
+ def self.define_pitch name, value
25
+ pitch = MTK::Core::Pitch.from_i(value)
26
+ const_set name, pitch
27
+ PITCHES << pitch
28
+ PITCH_NAMES << name
29
+ end
13
30
 
14
31
  # The values of all constants defined in this module
32
+ # @note This is populated dynamically so the documentation does not reflect the actual value
15
33
  PITCHES = []
16
34
 
17
35
  # The names of all constants defined in this module
36
+ # @note This is populated dynamically so the documentation does not reflect the actual value
18
37
  PITCH_NAMES = []
19
38
 
20
- 128.times do |note_number|
21
- pitch = MTK::Core::Pitch.from_i( note_number )
22
- PITCHES << pitch
23
-
24
- octave_str = pitch.octave.to_s.sub(/-/,'_') # '_1' for -1
25
- name = "#{pitch.pitch_class}#{octave_str}"
26
- PITCH_NAMES << name
27
-
28
- # TODO? also define lower case pseudo constants for consistency with the grammar?
29
-
30
- const_set name, pitch
31
- end
39
+ define_pitch 'C_1', 0
40
+ define_pitch 'Db_1', 1
41
+ define_pitch 'D_1', 2
42
+ define_pitch 'Eb_1', 3
43
+ define_pitch 'E_1', 4
44
+ define_pitch 'F_1', 5
45
+ define_pitch 'Gb_1', 6
46
+ define_pitch 'G_1', 7
47
+ define_pitch 'Ab_1', 8
48
+ define_pitch 'A_1', 9
49
+ define_pitch 'Bb_1', 10
50
+ define_pitch 'B_1', 11
51
+ define_pitch 'C0', 12
52
+ define_pitch 'Db0', 13
53
+ define_pitch 'D0', 14
54
+ define_pitch 'Eb0', 15
55
+ define_pitch 'E0', 16
56
+ define_pitch 'F0', 17
57
+ define_pitch 'Gb0', 18
58
+ define_pitch 'G0', 19
59
+ define_pitch 'Ab0', 20
60
+ define_pitch 'A0', 21
61
+ define_pitch 'Bb0', 22
62
+ define_pitch 'B0', 23
63
+ define_pitch 'C1', 24
64
+ define_pitch 'Db1', 25
65
+ define_pitch 'D1', 26
66
+ define_pitch 'Eb1', 27
67
+ define_pitch 'E1', 28
68
+ define_pitch 'F1', 29
69
+ define_pitch 'Gb1', 30
70
+ define_pitch 'G1', 31
71
+ define_pitch 'Ab1', 32
72
+ define_pitch 'A1', 33
73
+ define_pitch 'Bb1', 34
74
+ define_pitch 'B1', 35
75
+ define_pitch 'C2', 36
76
+ define_pitch 'Db2', 37
77
+ define_pitch 'D2', 38
78
+ define_pitch 'Eb2', 39
79
+ define_pitch 'E2', 40
80
+ define_pitch 'F2', 41
81
+ define_pitch 'Gb2', 42
82
+ define_pitch 'G2', 43
83
+ define_pitch 'Ab2', 44
84
+ define_pitch 'A2', 45
85
+ define_pitch 'Bb2', 46
86
+ define_pitch 'B2', 47
87
+ define_pitch 'C3', 48
88
+ define_pitch 'Db3', 49
89
+ define_pitch 'D3', 50
90
+ define_pitch 'Eb3', 51
91
+ define_pitch 'E3', 52
92
+ define_pitch 'F3', 53
93
+ define_pitch 'Gb3', 54
94
+ define_pitch 'G3', 55
95
+ define_pitch 'Ab3', 56
96
+ define_pitch 'A3', 57
97
+ define_pitch 'Bb3', 58
98
+ define_pitch 'B3', 59
99
+ define_pitch 'C4', 60
100
+ define_pitch 'Db4', 61
101
+ define_pitch 'D4', 62
102
+ define_pitch 'Eb4', 63
103
+ define_pitch 'E4', 64
104
+ define_pitch 'F4', 65
105
+ define_pitch 'Gb4', 66
106
+ define_pitch 'G4', 67
107
+ define_pitch 'Ab4', 68
108
+ define_pitch 'A4', 69
109
+ define_pitch 'Bb4', 70
110
+ define_pitch 'B4', 71
111
+ define_pitch 'C5', 72
112
+ define_pitch 'Db5', 73
113
+ define_pitch 'D5', 74
114
+ define_pitch 'Eb5', 75
115
+ define_pitch 'E5', 76
116
+ define_pitch 'F5', 77
117
+ define_pitch 'Gb5', 78
118
+ define_pitch 'G5', 79
119
+ define_pitch 'Ab5', 80
120
+ define_pitch 'A5', 81
121
+ define_pitch 'Bb5', 82
122
+ define_pitch 'B5', 83
123
+ define_pitch 'C6', 84
124
+ define_pitch 'Db6', 85
125
+ define_pitch 'D6', 86
126
+ define_pitch 'Eb6', 87
127
+ define_pitch 'E6', 88
128
+ define_pitch 'F6', 89
129
+ define_pitch 'Gb6', 90
130
+ define_pitch 'G6', 91
131
+ define_pitch 'Ab6', 92
132
+ define_pitch 'A6', 93
133
+ define_pitch 'Bb6', 94
134
+ define_pitch 'B6', 95
135
+ define_pitch 'C7', 96
136
+ define_pitch 'Db7', 97
137
+ define_pitch 'D7', 98
138
+ define_pitch 'Eb7', 99
139
+ define_pitch 'E7', 100
140
+ define_pitch 'F7', 101
141
+ define_pitch 'Gb7', 102
142
+ define_pitch 'G7', 103
143
+ define_pitch 'Ab7', 104
144
+ define_pitch 'A7', 105
145
+ define_pitch 'Bb7', 106
146
+ define_pitch 'B7', 107
147
+ define_pitch 'C8', 108
148
+ define_pitch 'Db8', 109
149
+ define_pitch 'D8', 110
150
+ define_pitch 'Eb8', 111
151
+ define_pitch 'E8', 112
152
+ define_pitch 'F8', 113
153
+ define_pitch 'Gb8', 114
154
+ define_pitch 'G8', 115
155
+ define_pitch 'Ab8', 116
156
+ define_pitch 'A8', 117
157
+ define_pitch 'Bb8', 118
158
+ define_pitch 'B8', 119
159
+ define_pitch 'C9', 120
160
+ define_pitch 'Db9', 121
161
+ define_pitch 'D9', 122
162
+ define_pitch 'Eb9', 123
163
+ define_pitch 'E9', 124
164
+ define_pitch 'F9', 125
165
+ define_pitch 'Gb9', 126
166
+ define_pitch 'G9', 127
32
167
 
33
168
  PITCHES.freeze
34
169
  PITCH_NAMES.freeze
35
170
 
36
- # Lookup the value of an pitch constant by name.
37
- # @example lookup value of 'C3'
38
- # MTK::Core::Pitches['C3']
39
- # @see Core::Pitch.from_s
40
- # @note Unlike {Core::Pitch.from_s} this method will accept either '_' (underscore) or '-' (minus) and treat it like '-' (minus)
41
- # @note Unlike {Core::Pitch.from_s} this method only accepts the accidental 'b'
42
- def self.[](name)
43
- begin
44
- const_get name.sub('-','_')
45
- rescue
46
- nil
47
- end
48
- end
49
-
50
171
  end
51
172
  end
52
173
  end
174
+
175
+
176
+
177
+ =begin
178
+
179
+ Script for generating the define_pitch statements in this file.
180
+ Run in the irb console after requiring 'mtk'
181
+
182
+ 128.times do |value|
183
+ pitch = MTK::Core::Pitch.from_i(value)
184
+ octave_str = pitch.octave.to_s.sub(/-/,'_') # '_1' for -1
185
+ name = "#{pitch.pitch_class}#{octave_str}"
186
+ puts " define_pitch '#{name}', #{value}"
187
+ end
188
+
189
+ =end