Class: Juicy::Note
Constant Summary collapse
- @@default_octave =
4
Instance Attribute Summary collapse
-
#distance_from_beat_in_milliseconds ⇒ Object
Returns the value of attribute distance_from_beat_in_milliseconds.
-
#duration ⇒ Object
readonly
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.
Class Method Summary collapse
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(name = "A", duration = "quarter", octave_change = 0) ⇒ Note
constructor
A new instance of Note.
- #inspect ⇒ Object
- #length ⇒ Object
- #play(options = {duration: 200, octave: (@octave-@@default_octave)}) ⇒ Object
- #play_prepared ⇒ Object
- #plays_during(beat) ⇒ Object
- #plays_during?(beat) ⇒ Boolean
- #prepare(options = {duration: 200, octave: (@octave-@@default_octave)}) ⇒ Object
- #size ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name = "A", duration = "quarter", octave_change = 0) ⇒ Note
Returns a new instance of Note.
12 13 14 15 16 17 |
# File 'lib/juicy/note.rb', line 12 def initialize(name = "A", duration = "quarter", octave_change = 0) @name = parse_note_name(name) @pitch = Pitch.new(@name) @duration = Duration.new(duration) @octave = @@default_octave + octave_change end |
Instance Attribute Details
#distance_from_beat_in_milliseconds ⇒ Object
Returns the value of attribute distance_from_beat_in_milliseconds.
10 11 12 |
# File 'lib/juicy/note.rb', line 10 def distance_from_beat_in_milliseconds @distance_from_beat_in_milliseconds end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
8 9 10 |
# File 'lib/juicy/note.rb', line 8 def duration @duration end |
#how_far_into_the_song_you_are ⇒ Object
Returns the value of attribute how_far_into_the_song_you_are.
9 10 11 |
# File 'lib/juicy/note.rb', line 9 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.
8 9 10 |
# File 'lib/juicy/note.rb', line 8 def name @name end |
#occupying_beat ⇒ Object (readonly)
Returns the value of attribute occupying_beat.
8 9 10 |
# File 'lib/juicy/note.rb', line 8 def @occupying_beat end |
#octave ⇒ Object (readonly)
Returns the value of attribute octave.
8 9 10 |
# File 'lib/juicy/note.rb', line 8 def octave @octave end |
#pitch ⇒ Object (readonly)
Returns the value of attribute pitch.
8 9 10 |
# File 'lib/juicy/note.rb', line 8 def pitch @pitch end |
#sum_of_queued_note_durations ⇒ Object
Returns the value of attribute sum_of_queued_note_durations.
9 10 11 |
# File 'lib/juicy/note.rb', line 9 def sum_of_queued_note_durations @sum_of_queued_note_durations end |
Class Method Details
.default_octave ⇒ Object
108 109 110 |
# File 'lib/juicy/note.rb', line 108 def self.default_octave @@default_octave end |
Instance Method Details
#+(interval) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/juicy/note.rb', line 68 def +(interval) step = PITCHES[@name]+interval octave_change = step/12 #mathy stuff to figure out how many octaves were traversed (cant assume just one was name = PITCHES.key((PITCHES[@name]+interval) % 12) Note.new(name, @octave-@@default_octave + octave_change) end |
#-(interval) ⇒ Object
75 76 77 |
# File 'lib/juicy/note.rb', line 75 def -(interval) Note.new(PITCHES.key((PITCHES[@name]-interval) % 12)) end |
#<=>(other_note) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/juicy/note.rb', line 79 def <=>(other_note) if same_octave self.pitch <=> other_note.pitch else self.octave <=> other_note.octave end end |
#duration_in_milliseconds(tempo) ⇒ Object
103 104 105 106 |
# File 'lib/juicy/note.rb', line 103 def duration_in_milliseconds(tempo) #puts tempo @duration.duration_in_milliseconds(tempo) end |
#initial_play_time ⇒ Object
99 100 101 |
# File 'lib/juicy/note.rb', line 99 def initial_play_time @initial_play_time end |
#initial_play_time=(time) ⇒ Object
95 96 97 |
# File 'lib/juicy/note.rb', line 95 def initial_play_time=(time) @initial_play_time = time end |
#inspect ⇒ Object
26 27 28 |
# File 'lib/juicy/note.rb', line 26 def inspect "#{@name}" end |
#length ⇒ Object
87 88 89 |
# File 'lib/juicy/note.rb', line 87 def length duration end |
#play(options = {duration: 200, octave: (@octave-@@default_octave)}) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/juicy/note.rb', line 30 def play( = {duration: 200, octave: (@octave-@@default_octave)}) if @name == :_ [:volume] = 0 end @pitch.play() end |
#play_prepared ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/juicy/note.rb', line 55 def play_prepared #puts @prepared_note.status #puts "playing" until @prepared_note.status.eql? "sleep" sleep 0.001 #puts @prepared_note.status #Thread.pass end #Thread.pass #puts "waking up" @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-@@default_octave)}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/juicy/note.rb', line 37 def prepare( = {duration: 200, octave: (@octave-@@default_octave)}) [:duration] = [:duration] || 200 [:octave] = [:octave] || (@octave-@@default_octave) if @name == :_ [:volume] = 0 end Thread.pass @prepared_note = @pitch.prepare() @prepared_note[:sleep_time] = @distance_from_beat_in_milliseconds/1000.0 #puts @prepared_note.status until @prepared_note.status.eql? "sleep" sleep 0.001 #puts @prepared_note.status end @prepared_note self end |
#size ⇒ Object
91 92 93 |
# File 'lib/juicy/note.rb', line 91 def size duration end |
#to_s ⇒ Object
19 20 21 22 23 24 |
# File 'lib/juicy/note.rb', line 19 def to_s name = @name[0] name += "#" if @name=~/sharp/ name += "b" if @name=~/flat/ "#{name}#{@octave}" end |