Class: Music

Inherits:
Object
  • Object
show all
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

Classes: NotFound, Type

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context_type, looping, frame_count) ⇒ Music

Creates a new instance of Music

Parameters:

  • context_type (Integer)

    A value between 0 and 6

  • looping (Boolean)
  • frame_count (Integer)


7
8
9
10
11
# File 'mrb_doc/models/music.rb', line 7

def initialize(context_type, looping, frame_count)
  # mrb_Music_initialize
  # src/mruby_integration/models/music.cpp
  Music.new
end

Instance Attribute Details

#context_typeInteger

Returns:

  • (Integer)


4
5
6
# File 'src/ruby/models/music.rb', line 4

def context_type
  @context_type
end

#frame_countInteger

Returns:

  • (Integer)


4
5
6
# File 'src/ruby/models/music.rb', line 4

def frame_count
  @frame_count
end

#loopingBoolean

Returns:

  • (Boolean)


10
11
12
# File 'src/ruby/models/music.rb', line 10

def looping
  @looping
end

#pitchFloat

Returns:

  • (Float)


7
8
9
# File 'src/ruby/models/music.rb', line 7

def pitch
  @pitch
end

#volumeFloat

Returns:

  • (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

Parameters:

  • path (String)

Returns:

Raises:



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

#lengthFloat

How long does this music go for?

Returns:

  • (Float)


79
80
81
# File 'src/ruby/models/music.rb', line 79

def length
  get_music_time_length(self)
end

#pausenil

Pauses the music, you will need to call Music#resume to start it again

Returns:

  • (nil)


67
68
69
# File 'src/ruby/models/music.rb', line 67

def pause
  pause_music_stream(self)
end

#playnil

Starts playing the music

Returns:

  • (nil)


42
43
44
# File 'src/ruby/models/music.rb', line 42

def play
  play_music_stream(self)
end

#playedFloat

How long has the music been played for this loop?

Returns:

  • (Float)


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?

Returns:

  • (Boolean)


55
56
57
# File 'src/ruby/models/music.rb', line 55

def playing?
  music_playing?(self)
end

#resumenil

Resumes the music playing

Returns:

  • (nil)


73
74
75
# File 'src/ruby/models/music.rb', line 73

def resume
  resume_music_stream(self)
end

#stopnil

Stops the music, you will need to call Music#play to start it again

Returns:

  • (nil)


61
62
63
# File 'src/ruby/models/music.rb', line 61

def stop
  stop_music_stream(self)
end

#to_hHash

Return the object represented by a Hash

Returns:

  • (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

#unloadnil

Unloads the music from memory

Returns:

  • (nil)


36
37
38
# File 'src/ruby/models/music.rb', line 36

def unload
  unload_music_stream(self)
end

#updatenil

This method should be called every update to keep the music playing smoothly

Returns:

  • (nil)


49
50
51
# File 'src/ruby/models/music.rb', line 49

def update
  update_music_stream(self)
end