Class: Osb::Sample

Inherits:
Object
  • Object
show all
Defined in:
lib/osb/sample.rb

Overview

Audio sample.

Instance Method Summary collapse

Constructor Details

#initialize(time:, layer:, file_path:, volume: 100) ⇒ Sample

Returns a new instance of Sample.

Parameters:

  • time (Integer)

    the timestamp that the sound should start playing.

  • layer (String)

    the layer you want the sound to be on.

  • file_path (String)

    filename of the audio.

  • volume (Integer) (defaults to: 100)

    indicate the relative loudness of the sound.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/osb/sample.rb', line 13

def initialize(time:, layer:, file_path:, volume: 100)
  Internal.assert_type!(layer, String, "layer")
  Internal.assert_value!(layer, Layer::ALL, "layer")
  Internal.assert_type!(file_path, String, "file_path")

  layer_ =
    case layer
    when Osb::Layer::Background
      0
    when Osb::Layer::Foreground
      1
    when Osb::Layer::Fail
      2
    when Osb::Layer::Pass
      3
    else
      raise InvalidValueError,
            "An audio sample can only exists in one of these layers: " +
              "Background, Foreground, Fail or Pass."
    end

  @command = "Sample,#{time},#{layer_},\"#{file_path}}\",#{volume}"
end