Class: Juicy::Note
Class Attribute Summary collapse
-
.default_octave ⇒ Object
readonly
Returns the value of attribute default_octave.
Instance Attribute Summary collapse
-
#distance_from_beat_in_milliseconds ⇒ Object
Returns the value of attribute distance_from_beat_in_milliseconds.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#how_far_into_the_song_you_are ⇒ Object
Returns the value of attribute how_far_into_the_song_you_are.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#occupying_beat ⇒ Object
readonly
Returns the value of attribute occupying_beat.
-
#octave ⇒ Object
readonly
Returns the value of attribute octave.
-
#pitch ⇒ Object
readonly
Returns the value of attribute pitch.
-
#sum_of_queued_note_durations ⇒ Object
Returns the value of attribute sum_of_queued_note_durations.
Instance Method Summary collapse
- #+(interval) ⇒ Object
- #-(interval) ⇒ Object
- #<=>(other_note) ⇒ Object
- #duration_in_milliseconds(tempo) ⇒ Object
- #initial_play_time ⇒ Object
- #initial_play_time=(time) ⇒ Object
-
#initialize(options = {name: "A", duration: :quarter, octave_change: 0}) ⇒ Note
constructor
A new instance of Note.
- #inspect ⇒ Object
- #length ⇒ Object
- #play(options = {duration: 200, octave: (@octave-Note.default_octave)}) ⇒ Object
- #play_prepared ⇒ Object
- #plays_during(beat) ⇒ Object
- #plays_during?(beat) ⇒ Boolean
- #prepare(options = {duration: 200, octave: (@octave-Note.default_octave)}) ⇒ Object
- #prev ⇒ Object
- #size ⇒ Object
- #succ ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(options = {name: "A", duration: :quarter, octave_change: 0}) ⇒ Note
Returns a new instance of Note.
15 16 17 18 19 20 21 22 23 |
# File 'lib/juicy/note.rb', line 15 def initialize( = {name: "A", duration: :quarter, octave_change: 0}) [:name] ||= "A" [:duration] ||= :quarter [:octave_change] ||= 0 @name = parse_note_name([:name]) @pitch = Pitch.new(@name) @duration = Duration.new([:duration]) @octave = Note.default_octave + [:octave_change] end |
Class Attribute Details
.default_octave ⇒ Object (readonly)
Returns the value of attribute default_octave.
8 9 10 |
# File 'lib/juicy/note.rb', line 8 def default_octave @default_octave end |
Instance Attribute Details
#distance_from_beat_in_milliseconds ⇒ Object
Returns the value of attribute distance_from_beat_in_milliseconds.
13 14 15 |
# File 'lib/juicy/note.rb', line 13 def distance_from_beat_in_milliseconds @distance_from_beat_in_milliseconds end |
#duration ⇒ Object
Returns the value of attribute duration.
11 12 13 |
# File 'lib/juicy/note.rb', line 11 def duration @duration end |
#how_far_into_the_song_you_are ⇒ Object
Returns the value of attribute how_far_into_the_song_you_are.
12 13 14 |
# File 'lib/juicy/note.rb', line 12 def how_far_into_the_song_you_are @how_far_into_the_song_you_are end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/juicy/note.rb', line 11 def name @name end |
#occupying_beat ⇒ Object (readonly)
Returns the value of attribute occupying_beat.
11 12 13 |
# File 'lib/juicy/note.rb', line 11 def @occupying_beat end |
#octave ⇒ Object (readonly)
Returns the value of attribute octave.
11 12 13 |
# File 'lib/juicy/note.rb', line 11 def octave @octave end |
#pitch ⇒ Object (readonly)
Returns the value of attribute pitch.
11 12 13 |
# File 'lib/juicy/note.rb', line 11 def pitch @pitch end |
#sum_of_queued_note_durations ⇒ Object
Returns the value of attribute sum_of_queued_note_durations.
12 13 14 |
# File 'lib/juicy/note.rb', line 12 def sum_of_queued_note_durations @sum_of_queued_note_durations end |
Instance Method Details
#+(interval) ⇒ Object
66 67 68 69 |
# File 'lib/juicy/note.rb', line 66 def +(interval) step(interval) Note.new(name: new_name, octave_change: octave_change) end |
#-(interval) ⇒ Object
71 72 73 74 |
# File 'lib/juicy/note.rb', line 71 def -(interval) step(-1*interval) Note.new(name: new_name, octave_change: octave_change) end |
#<=>(other_note) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/juicy/note.rb', line 76 def <=>(other_note) if same_octave(other_note) self.pitch <=> other_note.pitch else self.octave <=> other_note.octave end end |
#duration_in_milliseconds(tempo) ⇒ Object
108 109 110 |
# File 'lib/juicy/note.rb', line 108 def duration_in_milliseconds(tempo) @duration.duration_in_milliseconds(tempo) end |
#initial_play_time ⇒ Object
104 105 106 |
# File 'lib/juicy/note.rb', line 104 def initial_play_time @initial_play_time end |
#initial_play_time=(time) ⇒ Object
100 101 102 |
# File 'lib/juicy/note.rb', line 100 def initial_play_time=(time) @initial_play_time = time end |
#inspect ⇒ Object
32 33 34 |
# File 'lib/juicy/note.rb', line 32 def inspect "#{@name}#{@octave}" end |
#length ⇒ Object
92 93 94 |
# File 'lib/juicy/note.rb', line 92 def length duration end |
#play(options = {duration: 200, octave: (@octave-Note.default_octave)}) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/juicy/note.rb', line 36 def play( = {duration: 200, octave: (@octave-Note.default_octave)}) if @name == :_ [:volume] = 0 end @pitch.play() end |
#play_prepared ⇒ Object
59 60 61 62 63 64 |
# File 'lib/juicy/note.rb', line 59 def play_prepared until @prepared_note.status.eql? "sleep" sleep 0.001 end @prepared_note.wakeup end |
#plays_during(beat) ⇒ Object
112 113 114 |
# File 'lib/juicy/note.rb', line 112 def plays_during(beat) @occupying_beat = beat end |
#plays_during?(beat) ⇒ Boolean
116 117 118 |
# File 'lib/juicy/note.rb', line 116 def plays_during?(beat) beat == @occupying_beat end |
#prepare(options = {duration: 200, octave: (@octave-Note.default_octave)}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/juicy/note.rb', line 43 def prepare( = {duration: 200, octave: (@octave-Note.default_octave)}) [:duration] = [:duration] || 200 [:octave] = [:octave] || (@octave-Note.default_octave) if @name == :_ [:volume] = 0 end Thread.pass @prepared_note = @pitch.prepare() @prepared_note[:sleep_time] = @distance_from_beat_in_milliseconds/1000.0 until @prepared_note.status.eql? "sleep" sleep 0.001 end @prepared_note self end |
#prev ⇒ Object
88 89 90 |
# File 'lib/juicy/note.rb', line 88 def prev return (self-1) end |
#size ⇒ Object
96 97 98 |
# File 'lib/juicy/note.rb', line 96 def size duration end |
#succ ⇒ Object
84 85 86 |
# File 'lib/juicy/note.rb', line 84 def succ return (self+1) end |
#to_s ⇒ Object
25 26 27 28 29 30 |
# File 'lib/juicy/note.rb', line 25 def to_s name = @name[0] name += "#" if @name=~/sharp/ name += "b" if @name=~/flat/ "#{name}#{@octave}" end |