Class: Commands::Sound
- Inherits:
-
Object
- Object
- Commands::Sound
- Defined in:
- lib/commands/sound.rb
Overview
Implements the “Sound” block in NXT-G
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#control ⇒ Object
Returns the value of attribute control.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#file ⇒ Object
Returns the value of attribute file.
-
#note ⇒ Object
Returns the value of attribute note.
-
#repeat ⇒ Object
Returns the value of attribute repeat.
-
#volume ⇒ Object
TODO not sure how to set this with direct commands?.
-
#wait ⇒ Object
Returns the value of attribute wait.
Instance Method Summary collapse
-
#initialize(nxt) ⇒ Sound
constructor
A new instance of Sound.
-
#start ⇒ Object
execute the Sound command based on the properties specified.
-
#stop ⇒ Object
stop the Sound command.
Constructor Details
#initialize(nxt) ⇒ Sound
Returns a new instance of Sound.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/commands/sound.rb', line 29 def initialize(nxt) @nxt = nxt # defaults the same as NXT-G @action = :file @control = :play @volume = 75 @repeat = false @file = "Good Job.rso" @note = "C" @duration = 0.5 @wait = true end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
20 21 22 |
# File 'lib/commands/sound.rb', line 20 def action @action end |
#control ⇒ Object
Returns the value of attribute control.
21 22 23 |
# File 'lib/commands/sound.rb', line 21 def control @control end |
#duration ⇒ Object
Returns the value of attribute duration.
26 27 28 |
# File 'lib/commands/sound.rb', line 26 def duration @duration end |
#file ⇒ Object
Returns the value of attribute file.
24 25 26 |
# File 'lib/commands/sound.rb', line 24 def file @file end |
#note ⇒ Object
Returns the value of attribute note.
25 26 27 |
# File 'lib/commands/sound.rb', line 25 def note @note end |
#repeat ⇒ Object
Returns the value of attribute repeat.
23 24 25 |
# File 'lib/commands/sound.rb', line 23 def repeat @repeat end |
#volume ⇒ Object
TODO not sure how to set this with direct commands?
22 23 24 |
# File 'lib/commands/sound.rb', line 22 def volume @volume end |
#wait ⇒ Object
Returns the value of attribute wait.
27 28 29 |
# File 'lib/commands/sound.rb', line 27 def wait @wait end |
Instance Method Details
#start ⇒ Object
execute the Sound command based on the properties specified
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/commands/sound.rb', line 44 def start if @action == :file @nxt.play_sound_file(@file,@repeat) else @nxt.play_tone(@note.to_freq,(@duration * 1000).to_i) end # TODO figure out a logical way to repeat a tone without blocking execution if @wait if @action == :tone sleep(@duration) else # TODO don't know how to sleep until a sound file finishes end end end |
#stop ⇒ Object
stop the Sound command
63 64 65 |
# File 'lib/commands/sound.rb', line 63 def stop @nxt.stop_sound_playback end |