module ZXUtils::MusicBox::Multitrack

MusicBox Multitrack

A multi-track consists of the three tracks, each one for each of the AY-3-891x channels.

Each track of a multi-track is a MusicBox::Track class.

Before each multi-track command the tracks are being synchronized by applying wait command whenever the track falls behind other tracks in the number of execution ticks. To control synchronization see command: MultitrackCommands.synchronize_channels.

To create a custom multi-track you need to include the Multitrack module in your class representing the given multi-track.

class ChannelTracks1
    include ZXUtils::MusicBox::Multitrack
    #... multi-track commands follow
end

Such a multi-track can be included with the MusicBox::SongCommands.import_multitrack command of the Song.

Alternatively use MusicBox::SongCommands.multitrack command to define multi-tracks directly in the Song.

Commands

For the list of available commands see MultitrackCommands.

Attributes

channel_tracks[R]

An array containing compiled tracks for each channel.

resolver[R]

A resolver used by the compilation process.

Public Class Methods

new(resolver) click to toggle source

Instances of the derived classes are being created internally by the MusicBox::Song compilation process.

# File lib/zxutils/music_box/multitrack.rb, line 279
def initialize(resolver)
        @resolver = resolver
        @channel_tracks = Array.new(3) { |_| EmptyTrack.new(@resolver) }
        @ticks_behind_channels = [0...2**16, 0...2**16, 0...2**16]
        self.class.instance_variable_get('@channels'.freeze).each { |e| self << e }
end

Public Instance Methods

channel_track(channel) click to toggle source

Returns an instance of the compiled track for the given channel. A channel can be an integer: 0 to 2 or one of the symbols or strings: :a, :b, :c.

# File lib/zxutils/music_box/multitrack.rb, line 288
def channel_track(channel)
        channel = case channel
        when Symbol
                Resolver::CHANNEL_NAMES.index(channel)
        when Integer
                channel
        end
        raise ArgumentError, "unrecognized channel: #{channel}" unless channel
        @channel_tracks[channel]
end