Class: Wavify::DSL::TrackDefinition Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(name, sample_folder: nil, key_root: nil, scale: nil, safe_paths: false) ⇒ TrackDefinition

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 TrackDefinition.



558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/wavify/dsl.rb', line 558

def initialize(name, sample_folder: nil, key_root: nil, scale: nil, safe_paths: false)
  @name = name.to_sym
  @sample_folder = sample_folder
  @waveform = :sine
  @gain_db = 0.0
  @pan_position = 0.0
  @pattern_resolution = 16
  @note_resolution = 8
  @default_octave = 4
  @envelope = nil
  @notes_notation = nil
  @chords_notation = nil
  @effects = []
  @samples = {}
  @sample_options = {}
  @named_patterns = {}
  @primary_pattern = nil
  @synth_options = {}
  @key_root = key_root
  @scale = scale
  @chord_voicing = nil
  @safe_paths = safe_paths
end

Instance Attribute Details

#chord_voicingObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def chord_voicing
  @chord_voicing
end

#chords_notationObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def chords_notation
  @chords_notation
end

#default_octaveObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def default_octave
  @default_octave
end

#effectsObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def effects
  @effects
end

#envelopeObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def envelope
  @envelope
end

#gain_dbObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def gain_db
  @gain_db
end

#key_rootObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def key_root
  @key_root
end

#nameObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def name
  @name
end

#named_patternsObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def named_patterns
  @named_patterns
end

#note_resolutionObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def note_resolution
  @note_resolution
end

#notes_notationObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def notes_notation
  @notes_notation
end

#pan_positionObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def pan_position
  @pan_position
end

#pattern_resolutionObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def pattern_resolution
  @pattern_resolution
end

#sample_folderObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def sample_folder
  @sample_folder
end

#sample_optionsObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def sample_options
  @sample_options
end

#samplesObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def samples
  @samples
end

#scaleObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def scale
  @scale
end

#synth_optionsObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def synth_options
  @synth_options
end

#waveformObject (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 mutable track state compiled from DSL blocks.

Readers are used by SongDefinition rendering and sequencer conversion.



554
555
556
# File 'lib/wavify/dsl.rb', line 554

def waveform
  @waveform
end

Instance Method Details

#chords!(notation, default_octave: nil, voicing: nil) ⇒ 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.

Stores chord progression notation and optional octave override.



605
606
607
608
609
# File 'lib/wavify/dsl.rb', line 605

def chords!(notation, default_octave: nil, voicing: nil)
  @chords_notation = notation
  @default_octave = default_octave if default_octave
  @chord_voicing = voicing.to_sym if voicing
end

#effect!(name, **params) ⇒ 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.

Appends an effect configuration to the track.



654
655
656
# File 'lib/wavify/dsl.rb', line 654

def effect!(name, **params)
  @effects << { name: name.to_sym, params: params }
end

#effect_processorsObject

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.

Instantiates configured effect processor objects.



697
698
699
700
701
702
703
# File 'lib/wavify/dsl.rb', line 697

def effect_processors
  @effects.map do |effect|
    Wavify::Effects.build(effect.fetch(:name), **effect.fetch(:params))
  rescue Wavify::Error => e
    raise Wavify::SequencerError, e.message
  end
end

#envelope!(**params) ⇒ 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.

Builds and stores an ADSR envelope for sequencer notes.



649
650
651
# File 'lib/wavify/dsl.rb', line 649

def envelope!(**params)
  @envelope = Wavify::DSP::Envelope.new(**params)
end

#finalize!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.



705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
# File 'lib/wavify/dsl.rb', line 705

def finalize!
  return self if frozen?

  @sample_folder = @sample_folder&.dup&.freeze
  @notes_notation = @notes_notation&.dup&.freeze
  @chords_notation = deep_freeze(@chords_notation)
  @effects = deep_freeze(@effects)
  @samples = deep_freeze(@samples)
  @sample_options = deep_freeze(@sample_options)
  @named_patterns = deep_freeze(@named_patterns)
  @primary_pattern = @primary_pattern&.dup&.freeze
  @synth_options = deep_freeze(@synth_options)
  @envelope&.freeze
  freeze
end

#gain!(db) ⇒ 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.

Sets gain (dB) applied after rendering the track.



631
632
633
634
635
636
637
# File 'lib/wavify/dsl.rb', line 631

def gain!(db)
  unless db.is_a?(Numeric) && db.respond_to?(:finite?) && db.finite?
    raise Wavify::SequencerError, "gain must be a finite Numeric"
  end

  @gain_db = db.to_f
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.

Stores note quantization key/scale settings.



612
613
614
615
# File 'lib/wavify/dsl.rb', line 612

def key!(root, scale = :major)
  @key_root = root
  @scale = scale
end

#notes!(notation, resolution: nil, default_octave: nil) ⇒ 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.

Stores note notation and optional parser settings.



598
599
600
601
602
# File 'lib/wavify/dsl.rb', line 598

def notes!(notation, resolution: nil, default_octave: nil)
  @notes_notation = notation.to_s
  @note_resolution = resolution if resolution
  @default_octave = default_octave if default_octave
end

#pan!(position) ⇒ 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.

Sets stereo pan position (-1.0..1.0).



640
641
642
643
644
645
646
# File 'lib/wavify/dsl.rb', line 640

def pan!(position)
  unless position.is_a?(Numeric) && position.respond_to?(:finite?) && position.finite? && position.between?(-1.0, 1.0)
    raise Wavify::SequencerError, "pan must be a finite Numeric in -1.0..1.0"
  end

  @pan_position = position.to_f
end

#pattern!(name_or_notation, notation = nil, resolution: nil) ⇒ 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.

Registers a primary or named rhythm pattern.



588
589
590
591
592
593
594
595
# File 'lib/wavify/dsl.rb', line 588

def pattern!(name_or_notation, notation = nil, resolution: nil)
  if notation.nil?
    @primary_pattern = name_or_notation.to_s
  else
    @named_patterns[name_or_notation.to_sym] = notation.to_s
  end
  @pattern_resolution = resolution if resolution
end

#primary_patternObject

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 the primary pattern notation for sequencer rendering.



583
584
585
# File 'lib/wavify/dsl.rb', line 583

def primary_pattern
  @primary_pattern || @named_patterns.values.first
end

#sample!(key, path = nil, **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.

Registers a sample path keyed by a symbolic name.



618
619
620
621
622
# File 'lib/wavify/dsl.rb', line 618

def sample!(key, path = nil, **options)
  sample_key = key.to_sym
  @samples[sample_key] = resolve_sample_path(sample_key, path)
  @sample_options[sample_key] = normalize_sample_options!(options)
end

#sample_pattern_mapObject

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.

Builds sample trigger patterns from named/primary pattern notation.



681
682
683
684
685
686
687
688
689
690
691
692
693
694
# File 'lib/wavify/dsl.rb', line 681

def sample_pattern_map
  patterns = {}
  @named_patterns.each do |name, notation|
    patterns[name] = Wavify::Sequencer::Pattern.new(notation, resolution: @pattern_resolution)
  end

  if patterns.empty? && @primary_pattern && @samples.length == 1
    patterns[@samples.keys.first] = Wavify::Sequencer::Pattern.new(@primary_pattern, resolution: @pattern_resolution)
  elsif patterns.empty? && @primary_pattern && @samples.length > 1
    raise Wavify::SequencerError, "primary sample pattern is ambiguous with multiple samples; use named patterns"
  end

  patterns
end

#synth!(waveform, **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.

Configures synth waveform and generator options.



625
626
627
628
# File 'lib/wavify/dsl.rb', line 625

def synth!(waveform, **options)
  @waveform = waveform.to_sym
  @synth_options.merge!(options)
end

#to_sequencer_trackObject

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.

Converts DSL settings into a Sequencer::Track.



659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
# File 'lib/wavify/dsl.rb', line 659

def to_sequencer_track
  Wavify::Sequencer::Track.new(
    @name,
    pattern: primary_pattern,
    note_sequence: @notes_notation,
    chord_progression: @chords_notation,
    waveform: @waveform,
    synth_options: @synth_options,
    gain_db: @gain_db,
    pan_position: @pan_position,
    pattern_resolution: @pattern_resolution,
    note_resolution: @note_resolution,
    default_octave: @default_octave,
    envelope: @envelope,
    effects: effect_processors,
    key: @key_root,
    scale: @scale,
    chord_voicing: @chord_voicing
  )
end