Class: Wavify::DSL::Builder Private
- Inherits:
-
Object
- Object
- Wavify::DSL::Builder
- Defined in:
- lib/wavify/dsl.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
:nodoc: all
Instance Attribute Summary collapse
-
#default_bars ⇒ Object
readonly
private
Internal builder state used by the public build_definition entrypoint.
-
#format ⇒ Object
readonly
private
Internal builder state used by the public build_definition entrypoint.
Class Method Summary collapse
-
.build_definition(format:, tempo: 120, beats_per_bar: 4, swing: 0.5, default_bars: 1, random_seed: Random.new_seed, safe_paths: false, &block) ⇒ SongDefinition
private
Compiles a DSL block into a SongDefinition.
Instance Method Summary collapse
-
#arrange(&block) ⇒ Object
private
Defines arrangement sections for selective track playback by section.
- #bars(value) ⇒ Object private
- #beats_per_bar(value) ⇒ Object private
-
#initialize(format:, tempo: 120, beats_per_bar: 4, swing: 0.5, default_bars: 1, random_seed: Random.new_seed, safe_paths: false) ⇒ Builder
constructor
private
A new instance of Builder.
- #key(root, scale = :major) ⇒ Object private
- #lofi_drums_preset(name: :lofi_drums, sample_folder: @sample_folder) ⇒ Object private
- #preset(name, **options) ⇒ Object private
- #sample_folder(path) ⇒ Object private
- #swing(value) ⇒ Object private
- #tempo(value) ⇒ Object private
-
#to_song_definition ⇒ Object
private
Finalizes and returns an immutable SongDefinition.
-
#track(name, sample_folder: @sample_folder, &block) ⇒ Object
private
Defines a track block and stores its compiled configuration.
Constructor Details
#initialize(format:, tempo: 120, beats_per_bar: 4, swing: 0.5, default_bars: 1, random_seed: Random.new_seed, safe_paths: false) ⇒ Builder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Builder.
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 |
# File 'lib/wavify/dsl.rb', line 904 def initialize(format:, tempo: 120, beats_per_bar: 4, swing: 0.5, default_bars: 1, random_seed: Random.new_seed, safe_paths: false) raise Wavify::InvalidParameterError, "format must be Core::Format" unless format.is_a?(Wavify::Core::Format) @format = format @tempo = validate_tempo!(tempo) @beats_per_bar = () @swing = validate_swing!(swing) @default_bars = () @random_seed = validate_random_seed!(random_seed) @safe_paths = safe_paths == true @sample_folder = nil @key_root = nil @scale = nil @track_definitions = [] @arrangement_sections = [] end |
Instance Attribute Details
#default_bars ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal builder state used by the public Wavify::DSL.build_definition entrypoint.
880 881 882 |
# File 'lib/wavify/dsl.rb', line 880 def @default_bars end |
#format ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal builder state used by the public Wavify::DSL.build_definition entrypoint.
880 881 882 |
# File 'lib/wavify/dsl.rb', line 880 def format @format end |
Class Method Details
.build_definition(format:, tempo: 120, beats_per_bar: 4, swing: 0.5, default_bars: 1, random_seed: Random.new_seed, safe_paths: false, &block) ⇒ SongDefinition
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Compiles a DSL block into a SongDefinition.
889 890 891 892 893 894 895 896 897 898 899 900 901 902 |
# File 'lib/wavify/dsl.rb', line 889 def self.build_definition(format:, tempo: 120, beats_per_bar: 4, swing: 0.5, default_bars: 1, random_seed: Random.new_seed, safe_paths: false, &block) builder = new( format: format, tempo: tempo, beats_per_bar: , swing: swing, default_bars: , random_seed: random_seed, safe_paths: safe_paths ) builder.instance_eval(&block) if block builder.to_song_definition end |
Instance Method Details
#arrange(&block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Defines arrangement sections for selective track playback by section.
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 |
# File 'lib/wavify/dsl.rb', line 1005 def arrange(&block) builder = ArrangementBuilder.new begin builder.instance_eval(&block) if block rescue Wavify::SequencerError => e raise Wavify::SequencerError, "arrangement: #{e.}" end @arrangement_sections = builder.sections if @arrangement_sections.length > Wavify::Sequencer::Engine::MAX_ARRANGEMENT_SECTIONS raise Wavify::SequencerError, "arrangement exceeds #{Wavify::Sequencer::Engine::MAX_ARRANGEMENT_SECTIONS} sections" end end |
#bars(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
940 941 942 943 944 945 946 |
# File 'lib/wavify/dsl.rb', line 940 def (value) unless value.is_a?(Integer) && value.between?(1, Wavify::Sequencer::Engine::MAX_BARS) raise Wavify::SequencerError, "bars must be an Integer in 1..#{Wavify::Sequencer::Engine::MAX_BARS}" end @default_bars = value end |
#beats_per_bar(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
930 931 932 933 934 |
# File 'lib/wavify/dsl.rb', line 930 def (value) raise Wavify::SequencerError, "beats_per_bar must be a positive Integer" unless value.is_a?(Integer) && value.positive? @beats_per_bar = value end |
#key(root, scale = :major) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
954 955 956 957 |
# File 'lib/wavify/dsl.rb', line 954 def key(root, scale = :major) @key_root = root @scale = scale end |
#lofi_drums_preset(name: :lofi_drums, sample_folder: @sample_folder) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
991 992 993 994 995 996 997 998 999 1000 1001 1002 |
# File 'lib/wavify/dsl.rb', line 991 def lofi_drums_preset(name: :lofi_drums, sample_folder: @sample_folder) track(name, sample_folder: sample_folder) do pattern :kick, "x---x---x---x---" pattern :snare, "----x-------x---" pattern :hat, "x-x-x-x-x-x-x-x-" sample :kick, "kick.wav", gain: -2, trim: true sample :snare, "snare.wav", gain: -4, trim: true sample :hat, "hat.wav", gain: -9, pan: 0.15, trim: true effect :compressor, threshold: -18, ratio: 2.5, attack: 0.005, release: 0.08, makeup_gain: 2 gain(-3) end end |
#preset(name, **options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
959 960 961 962 963 964 965 966 |
# File 'lib/wavify/dsl.rb', line 959 def preset(name, **) case name.to_sym when :lofi_drums lofi_drums_preset(**) else raise Wavify::SequencerError, "unsupported preset: #{name.inspect}" end end |
#sample_folder(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
948 949 950 951 952 |
# File 'lib/wavify/dsl.rb', line 948 def sample_folder(path) raise Wavify::SequencerError, "sample_folder must be a String" unless path.is_a?(String) && !path.empty? @sample_folder = path end |
#swing(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
936 937 938 |
# File 'lib/wavify/dsl.rb', line 936 def swing(value) @swing = validate_swing!(value) end |
#tempo(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
922 923 924 925 926 927 928 |
# File 'lib/wavify/dsl.rb', line 922 def tempo(value) unless value.is_a?(Numeric) && value.respond_to?(:finite?) && value.finite? && value.positive? raise Wavify::SequencerError, "tempo must be a positive finite Numeric" end @tempo = value.to_f end |
#to_song_definition ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Finalizes and returns an immutable SongDefinition.
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 |
# File 'lib/wavify/dsl.rb', line 1020 def to_song_definition SongDefinition.new( format: @format, tempo: @tempo, beats_per_bar: @beats_per_bar, swing: @swing, default_bars: @default_bars, tracks: @track_definitions, sections: @arrangement_sections, random_seed: @random_seed ) end |
#track(name, sample_folder: @sample_folder, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Defines a track block and stores its compiled configuration.
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 |
# File 'lib/wavify/dsl.rb', line 969 def track(name, sample_folder: @sample_folder, &block) normalized_name = name.to_sym if @track_definitions.any? { |definition| definition.name == normalized_name } raise Wavify::SequencerError, "duplicate track name: #{normalized_name}" end definition = TrackDefinition.new( normalized_name, sample_folder: sample_folder, key_root: @key_root, scale: @scale, safe_paths: @safe_paths ) begin TrackBuilder.new(definition).instance_eval(&block) if block rescue Wavify::Error => e raise Wavify::SequencerError, "track :#{definition.name}: #{e.}" end @track_definitions << definition definition end |