Documentation
¶
Overview ¶
Package gnome is a library for building a nearly-realtime metro...gnomes. Get it? GET IT?! One would think there would already be such a thing, but given the complexities involved in getting decent timing, there was not. Supports WAV, MP3, and Ogg Vorbis as passthoughs from `gopxl/beep` (which stands on the shoulders of other giants).
This is not perfect, either. If the system is very busy, the rhythm will not be smooth. If the tempo is exceptionally high, the rhythm will not be smooth. On a normal system, doing nothing else, BPMs under 180 are almost always great.
Gnome was built from scratch expecting WASM as the target platform. Some decisions that may seem odd were made because of that. Most odd decisions are simply odd. The consuming app was written for my brother-in-law's music students: [MetroGnome](https://github.com/cognusion/metrognome).
Index ¶
- Variables
- func BufferToStreamer(buff Buffer) (beep.StreamSeekCloser, beep.Format, error)
- func FileToBuffer(filename string) (*recyclable.Buffer, error)
- func FromBPM(bpm int32) time.Duration
- func ToBPM(interval time.Duration) int32
- type Buffer
- type Gnome
- func (g *Gnome) Change(tempo int32)
- func (g *Gnome) Close()
- func (g *Gnome) IsPaused() bool
- func (g *Gnome) IsRunning() bool
- func (g *Gnome) Mute()
- func (g *Gnome) Pan()
- func (g *Gnome) Pause()
- func (g *Gnome) ReplaceStreamerFromBuffer(buff Buffer) error
- func (g *Gnome) Restart() error
- func (g *Gnome) SetTickFilter(tf TickFilter) error
- func (g *Gnome) Start()
- func (g *Gnome) Stop()
- type TickFilter
- type TickFunc
- type TimeSignature
Constants ¶
This section is empty.
Variables ¶
var ( // RPool is a recyclable.BufferPool RPool = recyclable.NewBufferPool() )
Functions ¶
func BufferToStreamer ¶
BufferToStreamer checks the first 12 bytes of the Buffer to see if it's a WAV, and tries to decode it as that or an MP3. Errors are returned if anything fails.
func FileToBuffer ¶
func FileToBuffer(filename string) (*recyclable.Buffer, error)
FileToBuffer opens and reads the filename into a Buffer, returning it or an error.
Types ¶
type Buffer ¶ added in v0.2.0
type Buffer = io.ReadSeekCloser
Buffer is our local interface to encapsulate all the interfaces
type Gnome ¶
type Gnome struct {
// TS tracks and reports the time signature information for the 'gnome.
TS *TimeSignature
// contains filtered or unexported fields
}
Gnome is a metro...gnome. Get it? Get it?!
func NewGnomeFromBuffer ¶ added in v0.3.0
func NewGnomeFromBuffer(buff Buffer, ts *TimeSignature, tickFunc TickFunc) (*Gnome, error)
NewGnomeFromBuffer takes a Buffer, a TimeSignature and an optional tickFunc to call when the 'gnome fires, and gives you a Gnome or an error. :)
func NewGnomeFromFile ¶ added in v0.3.0
func NewGnomeFromFile(soundFile string, ts *TimeSignature, tickFunc TickFunc) (*Gnome, error)
NewGnomeFromFile takes a filename, a TimeSignature and an optional tickFunc to call when the 'gnome fires, and gives you a Gnome or an error. :)
func (*Gnome) IsPaused ¶ added in v0.4.0
IsPaused returns if the 'gnome is paused. This should not be used for blocking or timing decisions
func (*Gnome) Pan ¶ added in v0.6.1
func (g *Gnome) Pan()
Pan toggles whether or not beats will alternate on speakers.
func (*Gnome) ReplaceStreamerFromBuffer ¶ added in v0.6.1
ReplaceStreamerFromBuffer attempts to replace the current steamer with a new one from the provided buffer.
func (*Gnome) Restart ¶
Restart will re-initialize some stopped components so the 'gnome can carry on.
func (*Gnome) SetTickFilter ¶ added in v0.5.2
func (g *Gnome) SetTickFilter(tf TickFilter) error
SetTickFilter installs a new tickFilter. A tickFilter is passed the beat count and returns true if the sound should be played for that beat
type TickFilter ¶ added in v0.5.2
TickFilter is passed the beat count, and returns true if the tick sound should be played
type TickFunc ¶ added in v0.5.0
type TickFunc func(int)
TickFunc is a function called during a tick event. The current beat number is passed to it. These functions must absolutely handle being called multiple times in quick succession, handling order, overlaps, and all of that jazz.
type TimeSignature ¶
TimeSignature is a mechaism to make tracking time signatures, and their changes, easier and safe.
func NewTimeSignature ¶ added in v0.3.0
func NewTimeSignature(beats, noteValue, tempo int32) *TimeSignature
NewTimeSignature returns an initialized TimeSignature.
func (*TimeSignature) FromString ¶
func (ts *TimeSignature) FromString(sig string) error
FromString takes a signature string (e.g. "4/4" or "6/8") and sets TimeSignature accordingly.
func (*TimeSignature) String ¶
func (ts *TimeSignature) String() string
String pretty-prints the values of the TimeSignature.
func (*TimeSignature) TempoFromDuration ¶
func (ts *TimeSignature) TempoFromDuration(interval time.Duration)
TempoFromDuration sets the Tempo based on the interval provided.
func (*TimeSignature) TempoToDuration ¶
func (ts *TimeSignature) TempoToDuration() time.Duration
TempoToDuration returns the tempo as a time.Duration.
func (*TimeSignature) ToString ¶
func (ts *TimeSignature) ToString() string
ToString returns the signature string (e.g. "4/4" or "6/8"), without the Tempo.