Class: GBTiles::GBT::Import::MODFile
- Inherits:
-
Object
- Object
- GBTiles::GBT::Import::MODFile
- Defined in:
- lib/gbtiles/gbt/import/mod_file.rb
Instance Attribute Summary collapse
-
#mod_data ⇒ Object
Returns the value of attribute mod_data.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ MODFile
constructor
A new instance of MODFile.
Constructor Details
Instance Attribute Details
#mod_data ⇒ Object
Returns the value of attribute mod_data.
12 13 14 |
# File 'lib/gbtiles/gbt/import/mod_file.rb', line 12 def mod_data @mod_data end |
Class Method Details
.open(file) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gbtiles/gbt/import/mod_file.rb', line 18 def self.open file import = GBTiles::GBT::Import::MODFile.new import.mod_data.name = GBTiles::DataType.string(file.read(20)) for i in 0..30 sample_data = file.read(30) sample = GBTiles::GBT::MODData::Sample.new sample.name = GBTiles::DataType.string!(sample_data, 22) sample.length = GBTiles::DataType.bword!(sample_data) sample.finetune = GBTiles::DataType.byte!(sample_data) sample.volume = GBTiles::DataType.byte!(sample_data) sample.repeat_point = GBTiles::DataType.bword!(sample_data) sample.repeat_length = GBTiles::DataType.bword!(sample_data) import.mod_data.samples << sample end import.mod_data.song_length = GBTiles::DataType.byte(file.read(1)) file.read(1) # unused for i in 0..127 import.mod_data.pattern_table << GBTiles::DataType.byte(file.read(1)) end import.mod_data.identifier = GBTiles::DataType.string(file.read(4)) for i in 0..63 pattern = GBTiles::GBT::MODData::Pattern.new for j in 0..63 pattern.rows << file.read(16) end import.mod_data.patterns << pattern end if import.mod_data.identifier != "M.K." then raise IOError, "Invalid identifier in .MOD: expected `M.K.` got `#{import.mod_data.identifier}`" end import end |