sequence

package
v3.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package sequence provides generators and options for creating audio sequences.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChordPattern

type ChordPattern struct {
	Pitches [][]synth.Pitch
	Holds   [][]time.Duration
}

A ChordPattern represents the order of pitches and holds for each of those pitches over a sequence of (potential) chords. Todo: pitchPattern is a subset of this, should it even exist?

func (*ChordPattern) GetChordPattern

func (cp *ChordPattern) GetChordPattern() *ChordPattern

GetChordPattern returns a pointer to a generator's chord pattern

type Generator

type Generator interface {
	Generate() *Sequence
}

A Generator stores settings to create a sequence

type HasChords

type HasChords interface {
	GetChordPattern() *ChordPattern
}

HasChords lets generators be built from chord Options if they have a pointer to a chord pattern

type HasHolds

type HasHolds interface {
	GetHoldPattern() *[]time.Duration
}

HasHolds enables generators to be built from HoldPattern and use the related option functions

type HasLength

type HasLength interface {
	GetLength() int
	SetLength(int)
}

type HasLoops

type HasLoops interface {
	GetLoop() bool
	SetLoop(bool)
}

type HasPitches

type HasPitches interface {
	GetPitchPattern() []synth.Pitch
	SetPitchPattern([]synth.Pitch)
}

type HasTicks

type HasTicks interface {
	GetTick() time.Duration
	SetTick(time.Duration)
}

type HasVolumes

type HasVolumes interface {
	GetVolumePattern() []float64
	SetVolumePattern([]float64)
}

type HasWaves

type HasWaves interface {
	GetWavePattern() []synth.Wave
	SetWavePattern([]synth.Wave)
}

type HoldPattern

type HoldPattern []time.Duration

A HoldPattern is a pattern that might loop on itself for how long notes should be held

func (*HoldPattern) GetHoldPattern

func (hp *HoldPattern) GetHoldPattern() *HoldPattern

GetHoldPattern lets composing HoldPattern satisfy HasHolds

type Length

type Length int

func (*Length) GetLength

func (l *Length) GetLength() int

func (*Length) SetLength

func (l *Length) SetLength(i int)

type Loop

type Loop bool

func (*Loop) GetLoop

func (l *Loop) GetLoop() bool

func (*Loop) SetLoop

func (l *Loop) SetLoop(b bool)

type Option

type Option func(Generator)

Option types are inserted into Constructors to create generators

func And

func And(opts ...Option) Option

And combines any number of options into a single option. And is a reminder that you can store combined settings to avoid having to rewrite them

func Chords

func Chords(cp ChordPattern) Option

Chords sets the generator's chord pattern

func HoldAt

func HoldAt(t time.Duration, n int) Option

HoldAt sets the n'th value in the entire play sequence to be Hold p. This could involve duplicating a pattern until it is long enough to reach n. Meaningless if the Hold pattern has not been set yet.

func HoldPatternAt

func HoldPatternAt(t time.Duration, n int) Option

HoldPatternAt sets the n'th value in the Hold pattern to be Hold p. Meaningless if the Hold pattern has not been set yet.

func Holds

func Holds(vs ...time.Duration) Option

Holds sets the generator's Hold pattern

func Loops

func Loops(b bool) Option

Loops sets the generator's Loop

func PitchAt

func PitchAt(p synth.Pitch, n int) Option

PitchAt sets the n'th value in the entire play sequence to be pitch p. This could involve duplicating a pattern until it is long enough to reach n. Meaningless if the pitch pattern has not been set yet.

func PitchPatternAt

func PitchPatternAt(p synth.Pitch, n int) Option

PitchPatternAt sets the n'th value in the pitch pattern to be pitch p. Meaningless if the pitch pattern has not been set yet.

func Pitches

func Pitches(ps ...synth.Pitch) Option

Pitches sets the generator's pitch pattern

func PlayLength

func PlayLength(i int) Option

func Ticks

func Ticks(t time.Duration) Option

Ticks sets the generator's Tick

func VolumeAt

func VolumeAt(v float64, n int) Option

VolumeAt sets the n'th value in the entire play sequence to be Volume p. This could involve duplicating a pattern until it is long enough to reach n. Meaningless if the Volume pattern has not been set yet.

func VolumePatternAt

func VolumePatternAt(v float64, n int) Option

VolumePatternAt sets the n'th value in the Volume pattern to be Volume p. Meaningless if the Volume pattern has not been set yet.

func Volumes

func Volumes(vs ...float64) Option

Volumes sets the generator's Volume pattern

func WaveAt

func WaveAt(w synth.Wave, n int) Option

WaveAt sets the n'th value in the entire play sequence to be Wave p. This could involve duplicating a pattern until it is long enough to reach n. Meaningless if the Wave pattern has not been set yet.

func WavePatternAt

func WavePatternAt(w synth.Wave, n int) Option

WavePatternAt sets the n'th value in the Wave pattern to be Wave p. Meaningless if the Wave pattern has not been set yet.

func Waves

func Waves(ws ...synth.Wave) Option

Waves sets the generator's Wave pattern

type PitchPattern

type PitchPattern []synth.Pitch

func (*PitchPattern) GetPitchPattern

func (pp *PitchPattern) GetPitchPattern() []synth.Pitch

func (*PitchPattern) SetPitchPattern

func (pp *PitchPattern) SetPitchPattern(ps []synth.Pitch)

type Sequence

type Sequence struct {
	// Sequences play patterns of audio
	// everything at Pattern[0] will be simultaneously Play()ed at
	// Sequence.Play()
	Pattern []*audio.Multi

	// Every tick, the next index in Pattern will be played by a Sequence
	// until the pattern is over.
	Ticker *time.Ticker
	// contains filtered or unexported fields
}

A Sequence is a timed pattern of simultaneously played audios.

func (*Sequence) Append

func (s *Sequence) Append(s2 *Sequence) (*Sequence, error)

Append creates a sequence by combining two sequences in order

func (*Sequence) Copy

func (s *Sequence) Copy() (audio.Audio, error)

Copy copies a sequence

func (*Sequence) Filter

func (s *Sequence) Filter(fs ...audio.Filter) (audio.Audio, error)

Filter for a sequence does nothing yet

func (*Sequence) Mix

func (s *Sequence) Mix(s2 *Sequence) (*Sequence, error)

Mix combines two sequences

func (*Sequence) MustCopy

func (s *Sequence) MustCopy() audio.Audio

MustCopy acts as copy but panics on errors

func (*Sequence) MustFilter

func (s *Sequence) MustFilter(fs ...audio.Filter) audio.Audio

MustFilter acts as filter, but does not respect errors.

func (*Sequence) Play

func (s *Sequence) Play() <-chan error

Play on a sequence plays the pattern encoded in the sequence until stopped

func (*Sequence) PlayLength

func (s *Sequence) PlayLength() time.Duration

PlayLength returns how long this sequence will play before looping or stopping. This does not include how long the last note is held beyond the tick duration

func (*Sequence) SetVolume

func (s *Sequence) SetVolume(int32) error

func (*Sequence) Stop

func (s *Sequence) Stop() error

Stop stops a sequence

type Tick

type Tick time.Duration

func (*Tick) GetTick

func (vp *Tick) GetTick() time.Duration

func (*Tick) SetTick

func (vp *Tick) SetTick(vs time.Duration)

type VolumePattern

type VolumePattern []float64

func (*VolumePattern) GetVolumePattern

func (vp *VolumePattern) GetVolumePattern() []float64

func (*VolumePattern) SetVolumePattern

func (vp *VolumePattern) SetVolumePattern(vs []float64)

type WaveGenerator

A WaveGenerator composes sets of simple waveforms as a sequence

func NewWaveGenerator

func NewWaveGenerator(opts ...Option) *WaveGenerator

NewWaveGenerator uses optional variadic syntax to enable any variant of a generator to be made

func (*WaveGenerator) Generate

func (wg *WaveGenerator) Generate() *Sequence

Generate generates a sequence from this wave generator

type WavePattern

type WavePattern []synth.Wave

func (*WavePattern) GetWavePattern

func (wp *WavePattern) GetWavePattern() []synth.Wave

func (*WavePattern) SetWavePattern

func (wp *WavePattern) SetWavePattern(ws []synth.Wave)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL