Class: SongParser
- Inherits:
-
Object
- Object
- SongParser
- Defined in:
- lib/songparser.rb
Overview
This class is used to parse a raw YAML song definition into domain objects (i.e. Song, Pattern, Track, and Kit). These domain objects can then be used by AudioEngine to generate the actual audio data that is saved to disk.
The sole public method is parse(). It takes a raw YAML string and returns a Song and Kit object (or raises an error if the YAML string couldn’t be parsed correctly).
Constant Summary collapse
- DONT_USE_STRUCTURE_WARNING =
"\n" + "WARNING! This song contains a 'Structure' section in the header.\n" + "As of BEATS 1.2.1, the 'Structure' section should be renamed 'Flow'.\n" + "You should change your song file, in a future version using 'Structure' will cause an error.\n"
- NO_SONG_HEADER_ERROR_MSG =
"Song must have a header. Here's an example: Song: Tempo: 120 Flow: - Verse: x2 - Chorus: x2"
Instance Method Summary collapse
-
#initialize ⇒ SongParser
constructor
A new instance of SongParser.
-
#parse(base_path, raw_yaml_string) ⇒ Object
Parses a raw YAML song definition and converts it into a Song and Kit object.
Constructor Details
#initialize ⇒ SongParser
Returns a new instance of SongParser.
26 27 |
# File 'lib/songparser.rb', line 26 def initialize() end |
Instance Method Details
#parse(base_path, raw_yaml_string) ⇒ Object
Parses a raw YAML song definition and converts it into a Song and Kit object.
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 62 63 64 65 66 67 68 69 |
# File 'lib/songparser.rb', line 31 def parse(base_path, raw_yaml_string) raw_song_components = hashify_raw_yaml(raw_yaml_string) unless raw_song_components[:folder] == nil base_path = raw_song_components[:folder] end song = Song.new() # 1.) Set tempo begin if raw_song_components[:tempo] != nil song.tempo = raw_song_components[:tempo] end rescue InvalidTempoError => detail raise SongParseError, "#{detail}" end # 2.) Build the kit begin kit = build_kit(base_path, raw_song_components[:kit], raw_song_components[:patterns]) rescue SoundFileNotFoundError => detail raise SongParseError, "#{detail}" rescue InvalidSoundFormatError => detail raise SongParseError, "#{detail}" end # 3.) Load patterns add_patterns_to_song(song, raw_song_components[:patterns]) # 4.) Set flow if raw_song_components[:flow] == nil raise SongParseError, "Song must have a Flow section in the header." else set_song_flow(song, raw_song_components[:flow]) end return song, kit end |