Class: Music
- Inherits:
-
Object
- Object
- Music
- Defined in:
- src/ruby/models/music.rb,
mrb_doc/models/music.rb
Overview
The Music class holds longer format sound files, very useful for background music.
Defined Under Namespace
Instance Attribute Summary collapse
Class Method Summary collapse
-
.load(path) ⇒ Music
Loads a music file from the specified path.
Instance Method Summary collapse
-
#initialize(context_type, looping, frame_count) ⇒ Music
constructor
Creates a new instance of Music.
-
#length ⇒ Float
How long does this music go for?.
-
#pause ⇒ nil
Pauses the music, you will need to call Music#resume to start it again.
-
#play ⇒ nil
Starts playing the music.
-
#played ⇒ Float
How long has the music been played for this loop?.
-
#playing? ⇒ Boolean
Is the music currently playing?.
-
#resume ⇒ nil
Resumes the music playing.
-
#stop ⇒ nil
Stops the music, you will need to call Music#play to start it again.
-
#to_h ⇒ Hash
Return the object represented by a Hash.
-
#unload ⇒ nil
Unloads the music from memory.
-
#update ⇒ nil
This method should be called every update to keep the music playing smoothly.
Constructor Details
Instance Attribute Details
#context_type ⇒ Integer
4 5 6 |
# File 'src/ruby/models/music.rb', line 4 def context_type @context_type end |
#frame_count ⇒ Integer
4 5 6 |
# File 'src/ruby/models/music.rb', line 4 def frame_count @frame_count end |
#looping ⇒ Boolean
10 11 12 |
# File 'src/ruby/models/music.rb', line 10 def looping @looping end |
#pitch ⇒ Float
7 8 9 |
# File 'src/ruby/models/music.rb', line 7 def pitch @pitch end |
#volume ⇒ Float
7 8 9 |
# File 'src/ruby/models/music.rb', line 7 def volume @volume end |
Class Method Details
.load(path) ⇒ Music
Loads a music file from the specified path
26 27 28 29 30 31 32 |
# File 'src/ruby/models/music.rb', line 26 def self.load(path) raise Music::NotFound.new("Could not find file at path \"#{path}\"") unless File.exist?(path) load_music_stream(path).tap { |music| music.volume = 1 music.pitch = 1 } end |
Instance Method Details
#length ⇒ Float
How long does this music go for?
79 80 81 |
# File 'src/ruby/models/music.rb', line 79 def length get_music_time_length(self) end |
#pause ⇒ nil
Pauses the music, you will need to call Music#resume to start it again
67 68 69 |
# File 'src/ruby/models/music.rb', line 67 def pause pause_music_stream(self) end |
#play ⇒ nil
Starts playing the music
42 43 44 |
# File 'src/ruby/models/music.rb', line 42 def play play_music_stream(self) end |
#played ⇒ Float
How long has the music been played for this loop?
85 86 87 |
# File 'src/ruby/models/music.rb', line 85 def played get_music_time_played(self) end |
#playing? ⇒ Boolean
Is the music currently playing?
55 56 57 |
# File 'src/ruby/models/music.rb', line 55 def (self) end |
#resume ⇒ nil
Resumes the music playing
73 74 75 |
# File 'src/ruby/models/music.rb', line 73 def resume resume_music_stream(self) end |
#stop ⇒ nil
Stops the music, you will need to call Music#play to start it again
61 62 63 |
# File 'src/ruby/models/music.rb', line 61 def stop stop_music_stream(self) end |
#to_h ⇒ Hash
Return the object represented by a Hash
14 15 16 17 18 19 20 |
# File 'src/ruby/models/music.rb', line 14 def to_h { context_type: context_type, looping: looping, frame_count: frame_count, } end |
#unload ⇒ nil
Unloads the music from memory
36 37 38 |
# File 'src/ruby/models/music.rb', line 36 def unload unload_music_stream(self) end |
#update ⇒ nil
This method should be called every update to keep the music playing smoothly
49 50 51 |
# File 'src/ruby/models/music.rb', line 49 def update update_music_stream(self) end |