Class: Beats::Kit
- Inherits:
-
Object
- Object
- Beats::Kit
- Defined in:
- lib/beats/kit.rb
Defined Under Namespace
Classes: LabelNotFoundError
Constant Summary collapse
- PLACEHOLDER_TRACK_NAME =
'empty_track_placeholder_name_234hkj32hjk4hjkhds23'
Instance Attribute Summary collapse
-
#bits_per_sample ⇒ Object
readonly
Returns the value of attribute bits_per_sample.
-
#num_channels ⇒ Object
readonly
Returns the value of attribute num_channels.
Instance Method Summary collapse
-
#get_sample_data(label) ⇒ Object
Returns the sample data for a sound contained in the Kit.
-
#initialize(items, num_channels, bits_per_sample) ⇒ Kit
constructor
A new instance of Kit.
Constructor Details
#initialize(items, num_channels, bits_per_sample) ⇒ Kit
Returns a new instance of Kit.
7 8 9 10 11 |
# File 'lib/beats/kit.rb', line 7 def initialize(items, num_channels, bits_per_sample) @items = items @num_channels = num_channels @bits_per_sample = bits_per_sample end |
Instance Attribute Details
#bits_per_sample ⇒ Object (readonly)
Returns the value of attribute bits_per_sample.
13 14 15 |
# File 'lib/beats/kit.rb', line 13 def bits_per_sample @bits_per_sample end |
#num_channels ⇒ Object (readonly)
Returns the value of attribute num_channels.
13 14 15 |
# File 'lib/beats/kit.rb', line 13 def num_channels @num_channels end |
Instance Method Details
#get_sample_data(label) ⇒ Object
Returns the sample data for a sound contained in the Kit. If the all sounds in the kit are mono, then this will be a flat Array of Fixnums between -32768 and 32767. Otherwise, this will be an Array of Fixnums pairs between -32768 and 32767.
label - The name of the sound to get sample data for. If the sound was defined in
the Kit section of a song file, this will generally be a descriptive label
such as "bass" or "snare". If defined in a track but not the kit, it will
generally be a file name such as "my_sounds/hihat/hi_hat.wav".
Examples
# If @num_channels is 1, a flat Array of Fixnums:
get_sample_data("bass")
# => [154, 7023, 8132, 2622, -132, 34, ..., -6702]
# If @num_channels is 2, a Array of Fixnums pairs:
get_sample_data("snare")
# => [[57, 1265], [-452, 10543], [-2531, 12643], [-6372, 11653], ..., [5482, 25673]]
Returns the sample data Array for the sound bound to label.
35 36 37 38 39 40 41 |
# File 'lib/beats/kit.rb', line 35 def get_sample_data(label) unless @items.has_key?(label) raise LabelNotFoundError, "Kit doesn't contain sound '#{label}'." end @items[label] end |