Class: Musicality::Part
- Inherits:
-
Object
show all
- Includes:
- Packable, Validatable
- Defined in:
- lib/musicality/notation/model/part.rb,
lib/musicality/composition/dsl/part_methods.rb,
lib/musicality/performance/midi/midi_settings.rb,
lib/musicality/performance/supercollider/synthdef.rb,
lib/musicality/printing/lilypond/lilypond_settings.rb,
lib/musicality/performance/supercollider/synthdef_settings.rb
Constant Summary
Constants included
from Packable
Packable::PACKED_CLASS_KEY
Instance Attribute Summary collapse
Instance Method Summary
collapse
#errors, #invalid?, #valid?, #validate
Methods included from Packable
#class_str, included, #init_params, #pack, pack_val, recover_class, unpack_val
Constructor Details
#initialize(start_dynamic, notes: [], dynamic_changes: {}, settings: []) {|_self| ... } ⇒ Part
Returns a new instance of Part.
12
13
14
15
16
17
18
19
|
# File 'lib/musicality/notation/model/part.rb', line 12
def initialize start_dynamic, notes: [], dynamic_changes: {}, settings: []
@notes = notes
@start_dynamic = start_dynamic
@dynamic_changes = dynamic_changes
@settings = settings
yield(self) if block_given?
end
|
Instance Attribute Details
#dynamic_changes ⇒ Object
Returns the value of attribute dynamic_changes.
10
11
12
|
# File 'lib/musicality/notation/model/part.rb', line 10
def dynamic_changes
@dynamic_changes
end
|
#notes ⇒ Object
Returns the value of attribute notes.
10
11
12
|
# File 'lib/musicality/notation/model/part.rb', line 10
def notes
@notes
end
|
#settings ⇒ Object
Returns the value of attribute settings.
10
11
12
|
# File 'lib/musicality/notation/model/part.rb', line 10
def settings
@settings
end
|
#start_dynamic ⇒ Object
Returns the value of attribute start_dynamic.
10
11
12
|
# File 'lib/musicality/notation/model/part.rb', line 10
def start_dynamic
@start_dynamic
end
|
Instance Method Details
#==(other) ⇒ Object
33
34
35
36
37
|
# File 'lib/musicality/notation/model/part.rb', line 33
def ==(other)
return (@notes == other.notes) &&
(@start_dynamic == other.start_dynamic) &&
(@dynamic_changes == other.dynamic_changes)
end
|
#check_dynamic_changes ⇒ Object
49
50
51
52
53
54
|
# File 'lib/musicality/notation/model/part.rb', line 49
def check_dynamic_changes
outofrange = @dynamic_changes.values.select {|v| !v.end_value.between?(0,1) }
if outofrange.any?
raise RangeError, "dynamic change values #{outofrange} are not between 0 and 1"
end
end
|
#check_methods ⇒ Object
21
22
23
|
# File 'lib/musicality/notation/model/part.rb', line 21
def check_methods
[:check_start_dynamic, :check_dynamic_changes]
end
|
#check_start_dynamic ⇒ Object
43
44
45
46
47
|
# File 'lib/musicality/notation/model/part.rb', line 43
def check_start_dynamic
unless @start_dynamic.between?(0,1)
raise RangeError, "start dynamic #{@start_dynamic} is not between 0 and 1"
end
end
|
#clone ⇒ Object
29
30
31
|
# File 'lib/musicality/notation/model/part.rb', line 29
def clone
Marshal.load(Marshal.dump(self))
end
|
#duration ⇒ Object
39
40
41
|
# File 'lib/musicality/notation/model/part.rb', line 39
def duration
return @notes.inject(0) { |sum, note| sum + note.duration }
end
|
#dynamic_change(new_dynamic, transition_dur: 0, offset: 0) ⇒ Object
4
5
6
7
8
9
|
# File 'lib/musicality/composition/dsl/part_methods.rb', line 4
def dynamic_change new_dynamic, transition_dur: 0, offset: 0
if transition_dur == 0
change = (transition_dur == 0) ? Change::Immediate.new(new_dynamic) : Change::Gradual.linear(new_dynamic, transition_dur)
self.dynamic_changes[self.duration + offset] = change
end
end
|
#find_settings(settings_class) ⇒ Object
62
63
64
|
# File 'lib/musicality/notation/model/part.rb', line 62
def find_settings settings_class
settings.find {|s| s.is_a? settings_class }
end
|
#lilypond_settings ⇒ Object
100
101
102
|
# File 'lib/musicality/printing/lilypond/lilypond_settings.rb', line 100
def lilypond_settings
find_settings(LilypondSettings)
end
|
#midi_settings ⇒ Object
122
123
124
|
# File 'lib/musicality/performance/midi/midi_settings.rb', line 122
def midi_settings
find_settings(MidiSettings)
end
|
#synthdef_settings ⇒ Object
52
53
54
|
# File 'lib/musicality/performance/supercollider/synthdef.rb', line 52
def synthdef_settings
find_settings(SuperCollider::SynthDef::Settings)
end
|
#transpose(interval) ⇒ Object
56
57
58
59
60
|
# File 'lib/musicality/notation/model/part.rb', line 56
def transpose interval
p = self.clone
p.notes.each {|n| n.transpose!(interval) }
return p
end
|
#validatables ⇒ Object
25
26
27
|
# File 'lib/musicality/notation/model/part.rb', line 25
def validatables
@notes
end
|