Documentation
¶
Index ¶
- Constants
- type ChannelInUseType
- type ControllerFade
- type InitConfig
- func (i *InitConfig) WithAudioDriver(driverName string) *InitConfig
- func (i *InitConfig) WithAudioDriverLinuxJack() *InitConfig
- func (i *InitConfig) WithAudioDriverLinuxPipewire() *InitConfig
- func (i *InitConfig) WithAudioDriverLinuxPulseAudio() *InitConfig
- func (i *InitConfig) WithAudioDriverSDL() *InitConfig
- func (i *InitConfig) WithBuffer(bufferSize int) *InitConfig
- func (i *InitConfig) WithDevice(deviceName string) *InitConfig
- func (i *InitConfig) WithFlag(flag uint32) *InitConfig
- func (i *InitConfig) WithNoDebug() *InitConfig
- func (i *InitConfig) WithSampleRate(sampleRate int) *InitConfig
- type SunvoxChannel
- func (c *SunvoxChannel) BPM() float32
- func (s *SunvoxChannel) Close() error
- func (s *SunvoxChannel) CurrentLine() int
- func (s *SunvoxChannel) CurrentSignalLevel() (float32, float32)
- func (s *SunvoxChannel) CustomLoopEnd() int
- func (s *SunvoxChannel) CustomLoopStart() int
- func (s *SunvoxChannel) ForEachModule(forEach func(module *SunvoxModule) bool) error
- func (s *SunvoxChannel) ForEachPattern(forEach func(pattern *SunvoxPattern) bool)
- func (s *SunvoxChannel) HasCustomLoop() bool
- func (s *SunvoxChannel) IsAtEndOfSong() bool
- func (s *SunvoxChannel) IsLooping() bool
- func (s *SunvoxChannel) IsPlaying() bool
- func (s *SunvoxChannel) IsValid() bool
- func (c *SunvoxChannel) LPM() float32
- func (s *SunvoxChannel) Length() (time.Duration, error)
- func (s *SunvoxChannel) LengthInFrames() int
- func (s *SunvoxChannel) LengthInLines() int
- func (s *SunvoxChannel) LoadFileFromBytes(data []byte) error
- func (s *SunvoxChannel) LoadFileFromFS(fileSys fs.FS, filename string) error
- func (s *SunvoxChannel) LoadFileFromPath(filepath string) error
- func (s *SunvoxChannel) Lock() error
- func (c *SunvoxChannel) ModuleByIndex(moduleIndex int) *SunvoxModule
- func (c *SunvoxChannel) ModuleByName(moduleName string) *SunvoxModule
- func (c *SunvoxChannel) ModuleCount() (int, error)
- func (c *SunvoxChannel) OutputModule() *SunvoxModule
- func (s *SunvoxChannel) PatternByIndex(patternIndex int) *SunvoxPattern
- func (s *SunvoxChannel) PatternByName(name string) *SunvoxPattern
- func (s *SunvoxChannel) PatternCount() (int, error)
- func (s *SunvoxChannel) PauseAudioEngine() error
- func (s *SunvoxChannel) Play() error
- func (s *SunvoxChannel) PlayFromBeginning() error
- func (s *SunvoxChannel) ProjectFilename() string
- func (s *SunvoxChannel) ProjectName() string
- func (s *SunvoxChannel) ResetCustomLoop()
- func (s *SunvoxChannel) ResumeAudioEngine() error
- func (s *SunvoxChannel) Seek(lineNum int) error
- func (s *SunvoxChannel) SendEvent(trackNum, note, velocity, module, ctrlEffect, parameterValue int) error
- func (c *SunvoxChannel) SetBPM(bpm float32) error
- func (s *SunvoxChannel) SetCustomLoop(startX, endX int)
- func (s *SunvoxChannel) SetEventTimestamp(setTimestamp bool, timestamp uint32) error
- func (s *SunvoxChannel) SetLooping(loop bool) error
- func (s *SunvoxChannel) SetOnCurrentLineChange(pollResolution time.Duration, onLinechange func(line int) bool)
- func (s *SunvoxChannel) SetOnPatternTouch(pollResolution time.Duration, ...)
- func (s *SunvoxChannel) SetProjectFilename(fname string)
- func (s *SunvoxChannel) SetProjectName(name string) error
- func (c *SunvoxChannel) SetTPL(tpl int) error
- func (s *SunvoxChannel) SetVolume(volume float32)
- func (s *SunvoxChannel) Stop() error
- func (c *SunvoxChannel) TPL() int
- func (c *SunvoxChannel) TPM() float32
- func (s *SunvoxChannel) Unlock() error
- func (s *SunvoxChannel) Volume() (float32, error)
- type SunvoxEngine
- func (e *SunvoxEngine) ChannelByFilename(filename string) *SunvoxChannel
- func (e *SunvoxEngine) ChannelByID(id any, inUse ChannelInUseType) *SunvoxChannel
- func (e *SunvoxEngine) ChannelByIndex(index int) *SunvoxChannel
- func (e *SunvoxEngine) CreateChannel(id any) (*SunvoxChannel, error)
- func (e *SunvoxEngine) Deinit() error
- func (e *SunvoxEngine) ForEachChannel(forEach func(channel *SunvoxChannel) bool)
- func (e *SunvoxEngine) Init(libraryPath string, config *InitConfig) error
- func (e *SunvoxEngine) InitFromDirectory(libraryBaseDirectoryPath string, config *InitConfig) error
- func (e *SunvoxEngine) SampleRate() (int, error)
- func (s *SunvoxEngine) Ticks() uint32
- func (s *SunvoxEngine) TicksPerSecond() uint32
- type SunvoxModule
- func (m *SunvoxModule) Connect(dest *SunvoxModule) error
- func (m *SunvoxModule) ControllerMaximum(ctrlNum int) (int, error)
- func (m *SunvoxModule) ControllerMinimum(ctrlNum int) (int, error)
- func (m *SunvoxModule) ControllerName(ctrlNum int) (string, error)
- func (m *SunvoxModule) ControllerValue(ctrlNum int) (int, error)
- func (m *SunvoxModule) Disconnect(dest *SunvoxModule) error
- func (m *SunvoxModule) Finetune() uint32
- func (m *SunvoxModule) Flags() (int32, error)
- func (m *SunvoxModule) IsValid() bool
- func (m *SunvoxModule) Name() string
- func (m *SunvoxModule) RelativeNote() uint32
- func (m *SunvoxModule) SetBSM(bypass, solo, mute bool) error
- func (m *SunvoxModule) SetControllerValue(ctrlNum, value int) error
- func (m *SunvoxModule) SetFinetune(finetune int) error
- func (m *SunvoxModule) SetRelativeNote(relativeNote int) error
- type SunvoxPattern
- func (p *SunvoxPattern) CustomLooplessX() int
- func (p *SunvoxPattern) CustomLooplessX2() int
- func (p *SunvoxPattern) Data() (*SunvoxPatternData, error)
- func (p *SunvoxPattern) IsValid() bool
- func (p *SunvoxPattern) LineCount() (int, error)
- func (p *SunvoxPattern) Move(dx, dy int) error
- func (p *SunvoxPattern) Name() string
- func (p *SunvoxPattern) SetMute(muted bool) (bool, error)
- func (p *SunvoxPattern) SetXY(x, y int) error
- func (p *SunvoxPattern) TrackCount() (int, error)
- func (p *SunvoxPattern) X() int
- func (p *SunvoxPattern) X2() int
- func (p *SunvoxPattern) Y() int
- type SunvoxPatternData
- func (s SunvoxPatternData) Controller(trackNum, lineNum int) (uint16, error)
- func (s SunvoxPatternData) ControllerValue(trackNum, lineNum int) (uint16, error)
- func (s SunvoxPatternData) LineCount() int
- func (s SunvoxPatternData) Module(trackNum, lineNum int) (uint16, error)
- func (s SunvoxPatternData) Note(trackNum, lineNum int) (uint8, error)
- func (s SunvoxPatternData) SetController(trackNum, lineNum int, controllerNumber uint16) error
- func (s SunvoxPatternData) SetControllerValue(trackNum, lineNum int, value uint16) error
- func (s SunvoxPatternData) SetModule(trackNum, lineNum int, moduleNumber uint16) error
- func (s SunvoxPatternData) SetNote(trackNum, lineNum int, noteValue uint8) error
- func (s SunvoxPatternData) SetVelocity(trackNum, lineNum int, velocity uint8) error
- func (s SunvoxPatternData) TrackCount() int
- func (s SunvoxPatternData) Velocity(trackNum, lineNum int) (uint8, error)
- type SunvoxPatternNoteData
- type VolumeFade
Constants ¶
const ( InitFlagNoDebugOutput = 1 << iota InitFlagUserAudioCallback InitFlagAudioInt16 InitFlagAudioFloat32 InitFlagOneThread )
const ( ModuleFlagExists = 1 << iota ModuleFlagGenerator ModuleFlagEffect ModuleFlagMute ModuleFlagSolo ModuleFlagBypass )
const ( NoteCommandNoteOff = 128 + iota NoteCommandAllNotesOff // send "note off" to all modules; NoteCommandCleanSynths // stop all modules - clear their internal buffers and put them into standby mode; NoteCommandStop NoteCommandPlay NoteCommandSetPitch // set the pitch specified in column XXYY, where 0x0000 - highest possible pitch, 0x7800 - lowest pitch (note C0); one semitone = 0x100; NoteCommandCleanModule // stop the module - clear its internal buffers and put it into standby mode. )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChannelInUseType ¶
type ChannelInUseType int
const ( ChannelAny ChannelInUseType = iota // Return any channel with a matching ID, regardless of if it's in use or not ChannelInUse // Return any channel with a matching ID that is currently in use; otherwise, nil ChannelInUseMaybe // Return any channel with a matching ID that is currently in use if possible; otherwise, any channel that matches ID ChannelNotInUse // Return any channel with a matching ID that is currently not in use; otherwise nil ChannelNotInUseMaybe // Return any channel with a matching ID that is currently not in use if possible; otherwise, any channel that matches ID )
type ControllerFade ¶
type ControllerFade struct { Module *SunvoxModule Controller int // contains filtered or unexported fields }
func NewControllerFade ¶
func NewControllerFade(start, end int, seconds float32, module *SunvoxModule, controller int) *ControllerFade
func (*ControllerFade) Restart ¶
func (f *ControllerFade) Restart()
type InitConfig ¶
func NewInitConfig ¶
func NewInitConfig() *InitConfig
func (*InitConfig) WithAudioDriver ¶
func (i *InitConfig) WithAudioDriver(driverName string) *InitConfig
The audio driver to be used; can be something like pulse on Linux, dsound, mmsound, asio, or maybe sdl on Windows?
func (*InitConfig) WithAudioDriverLinuxJack ¶
func (i *InitConfig) WithAudioDriverLinuxJack() *InitConfig
Set the audio driver to be used to Jack on Linux. Doesn't do anything on other OSes.
func (*InitConfig) WithAudioDriverLinuxPipewire ¶
func (i *InitConfig) WithAudioDriverLinuxPipewire() *InitConfig
Set the audio driver to be used to Pipewire on Linux. Doesn't do anything on other OSes.
func (*InitConfig) WithAudioDriverLinuxPulseAudio ¶
func (i *InitConfig) WithAudioDriverLinuxPulseAudio() *InitConfig
Set the audio driver to be used to PulseAudio on Linux. Doesn't do anything on other OSes.
func (*InitConfig) WithAudioDriverSDL ¶
func (i *InitConfig) WithAudioDriverSDL() *InitConfig
Set the audio driver to be used to SDL on any OSes that support it.
func (*InitConfig) WithBuffer ¶
func (i *InitConfig) WithBuffer(bufferSize int) *InitConfig
The preferred buffer size to initialize the engine with; note that the engine may not be able to initialize with this exact buffer size.
func (*InitConfig) WithDevice ¶
func (i *InitConfig) WithDevice(deviceName string) *InitConfig
The device to be used; something like "hw:0,0" on Linux for the first audio device
func (*InitConfig) WithFlag ¶
func (i *InitConfig) WithFlag(flag uint32) *InitConfig
func (*InitConfig) WithNoDebug ¶
func (i *InitConfig) WithNoDebug() *InitConfig
func (*InitConfig) WithSampleRate ¶
func (i *InitConfig) WithSampleRate(sampleRate int) *InitConfig
WithSampleRate sets the sample rate of the configuration to the specified value.
type SunvoxChannel ¶
SunvoxChannel represents a channel of audio playback. Each channel can play, seek / rewind, load a .sunvox file, etc.
func (*SunvoxChannel) BPM ¶
func (c *SunvoxChannel) BPM() float32
BPM returns the beats per minute for the song in the channel as a float32 for easy speed multiplication.
func (*SunvoxChannel) Close ¶
func (s *SunvoxChannel) Close() error
Close closes the channel and removes it from playback. If the SunvoxChannel is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxChannel) CurrentLine ¶
func (s *SunvoxChannel) CurrentLine() int
CurrentLine returns the current line of playback for the Sunvox project playing through the Channel.
func (*SunvoxChannel) CurrentSignalLevel ¶
func (s *SunvoxChannel) CurrentSignalLevel() (float32, float32)
CurrentSignalLevel returns the current signal level of the engine, ranging from 0 to 1 for the left and right audio channels.
func (*SunvoxChannel) CustomLoopEnd ¶
func (s *SunvoxChannel) CustomLoopEnd() int
CustomLoopEnd returns the end of the custom loop, if one is set. If one is not set, then it returns -1.
func (*SunvoxChannel) CustomLoopStart ¶
func (s *SunvoxChannel) CustomLoopStart() int
CustomLoopStart returns the start of the custom loop, if one is set. If one is not set, then it returns -1.
func (*SunvoxChannel) ForEachModule ¶
func (s *SunvoxChannel) ForEachModule(forEach func(module *SunvoxModule) bool) error
ForEachModule iterates through all modules in the project to execute a given function (forEach()) for each module. If the function returns false, the function will stop iteration.
func (*SunvoxChannel) ForEachPattern ¶
func (s *SunvoxChannel) ForEachPattern(forEach func(pattern *SunvoxPattern) bool)
ForEachPattern iterates through all patterns contained in the SunvoxChannel and executes the provided forEach function on each one. If the function returns false, the function stops iterating through the pattern set.
func (*SunvoxChannel) HasCustomLoop ¶
func (s *SunvoxChannel) HasCustomLoop() bool
HasCustomLoop returns if a custom loop is set.
func (*SunvoxChannel) IsAtEndOfSong ¶
func (s *SunvoxChannel) IsAtEndOfSong() bool
Returns if the channel is at the end of the song (only if the song does not loop).
func (*SunvoxChannel) IsLooping ¶
func (s *SunvoxChannel) IsLooping() bool
IsLooping returns if the SunvoxChannel is set to loop audio playback (which is the default).
func (*SunvoxChannel) IsPlaying ¶
func (s *SunvoxChannel) IsPlaying() bool
Returns if the channel is currently playing back audio. This will return true even if a one-shot / non-looped song is stopped at the end of the song.
func (*SunvoxChannel) IsValid ¶
func (s *SunvoxChannel) IsValid() bool
IsValid returns if the SunvoxChannel has data loaded.
func (*SunvoxChannel) LPM ¶
func (c *SunvoxChannel) LPM() float32
LPM returns the number of lines per minute of the project in the channel.
func (*SunvoxChannel) Length ¶
func (s *SunvoxChannel) Length() (time.Duration, error)
Length returns the length of the project as a time.Duration. If the SunvoxChannel is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxChannel) LengthInFrames ¶
func (s *SunvoxChannel) LengthInFrames() int
LengthInFrames returns the length of the project in frames.
func (*SunvoxChannel) LengthInLines ¶
func (s *SunvoxChannel) LengthInLines() int
LengthInFrames returns the length of the project in frames.
func (*SunvoxChannel) LoadFileFromBytes ¶
func (s *SunvoxChannel) LoadFileFromBytes(data []byte) error
LoadFile loads a slice of bytes obtained from reading a .sunvox file.
All loading functions will fail if a Channel has already begun to play back audio from a Sunvox Project. If you want to load a different file, close the channel and reopen it.
func (*SunvoxChannel) LoadFileFromFS ¶
func (s *SunvoxChannel) LoadFileFromFS(fileSys fs.FS, filename string) error
LoadFileFromFS loads a file of the provided filename from the given file system.
func (*SunvoxChannel) LoadFileFromPath ¶
func (s *SunvoxChannel) LoadFileFromPath(filepath string) error
LoadFileFromPath simply loads a file from the given filepath.
func (*SunvoxChannel) Lock ¶
func (s *SunvoxChannel) Lock() error
Locks the channel for simultaneous read/write from different threads / goroutines for the same channel. Some functions marked as "USE LOCK/UNLOCK" can't work without locking at all. If the SunvoxChannel is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxChannel) ModuleByIndex ¶
func (c *SunvoxChannel) ModuleByIndex(moduleIndex int) *SunvoxModule
ModuleByIndex returns a module by the given index - this can be hexadecimal (e.g. 0x1a) to match the module's index in Sunvox.
func (*SunvoxChannel) ModuleByName ¶
func (c *SunvoxChannel) ModuleByName(moduleName string) *SunvoxModule
ModuleByName returns the module by the specified moduleName. If a module with the specified name cannot be found, the function returns nil.
func (*SunvoxChannel) ModuleCount ¶
func (c *SunvoxChannel) ModuleCount() (int, error)
ModuleCount returns the number of modules in the project. If the SunvoxChannel is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxChannel) OutputModule ¶
func (c *SunvoxChannel) OutputModule() *SunvoxModule
OutputModule returns the output module for the SunvoxChannel.
func (*SunvoxChannel) PatternByIndex ¶
func (s *SunvoxChannel) PatternByIndex(patternIndex int) *SunvoxPattern
PatternByIndex returnss the specified numeric patternIndex argument. If patternIndex is outside of the range of patterns in the song, PatternByIndex will return nil.
func (*SunvoxChannel) PatternByName ¶
func (s *SunvoxChannel) PatternByName(name string) *SunvoxPattern
PatternByName returns a Pattern with the specified name; if it doesn't exist, PatternByName will return nil.
func (*SunvoxChannel) PatternCount ¶
func (s *SunvoxChannel) PatternCount() (int, error)
PatternCount returns the number of patterns in the channel, and an error if it was impossible to determine. If the SunvoxChannel is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxChannel) PauseAudioEngine ¶
func (s *SunvoxChannel) PauseAudioEngine() error
PauseAudioEngine pauses the global audio playback engine in Sunvox for the project in this SunvoxChannel. When paused, all audio stops (including echos, delays, etc).
This does not pause the playback state of the project (i.e. if it was playing a song, it still is, even if the audio engine is paused, regardless of if a song is playing.).
If the SunvoxChannel is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxChannel) Play ¶
func (s *SunvoxChannel) Play() error
Play plays the song contained within the SunvoxChannel from wherever the playhead currently is. It will also resume playback on stopped SunvoxChannels.
If the SunvoxChannel is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxChannel) PlayFromBeginning ¶
func (s *SunvoxChannel) PlayFromBeginning() error
PlayFromBeginning plays the song contained within the SunvoxChannel from the beginning (line number 0).
If the SunvoxChannel is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxChannel) ProjectFilename ¶
func (s *SunvoxChannel) ProjectFilename() string
ProjectFilename returns the project filename if the project was loaded through LoadFromFS or LoadFromPath. If it was loaded through LoadFileFromBytes(), this function will just return an empty string.
func (*SunvoxChannel) ProjectName ¶
func (s *SunvoxChannel) ProjectName() string
ProjectName returns the name for the project loaded in the channel. If there is an issue getting the song name, the function will just return an empty string.
func (*SunvoxChannel) ResetCustomLoop ¶
func (s *SunvoxChannel) ResetCustomLoop()
ResetCustomLoop resets any custom loop by moving Patterns back to their original locations.
func (*SunvoxChannel) ResumeAudioEngine ¶
func (s *SunvoxChannel) ResumeAudioEngine() error
ResumeAudioEngine resumes the global audio playback engine in Sunvox for the project in this SunvoxChannel. When resumed, any executing audio continues (including echos, delays, etc).
If the SunvoxChannel is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxChannel) Seek ¶
func (s *SunvoxChannel) Seek(lineNum int) error
Seek seeks playback to the given line number.
If the SunvoxChannel is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxChannel) SendEvent ¶
func (s *SunvoxChannel) SendEvent(trackNum, note, velocity, module, ctrlEffect, parameterValue int) error
func (*SunvoxChannel) SetBPM ¶
func (c *SunvoxChannel) SetBPM(bpm float32) error
SetBPM sets the BPM for playback in the channel to the desired BPM (cast down to integers), with a minimum of 32 BPM. If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxChannel) SetCustomLoop ¶
func (s *SunvoxChannel) SetCustomLoop(startX, endX int)
SetCustomLoop loops a stretch of patterns between two line numbers by isolating them. This is done by moving all other patterns to the left, and aligning the patterns between the ranges specified to start at line 0 (so normal playback with looping enabled goes from line 0 to the end of the pattern range specified).
Be sure to restart playback from the beginning / line 0 after calling SetCustomLoop, as Sunvox's engine finds the bounds of the current song for looping / ending purposes when playback is initiated.
func (*SunvoxChannel) SetEventTimestamp ¶
func (s *SunvoxChannel) SetEventTimestamp(setTimestamp bool, timestamp uint32) error
SetEventTimestamps sets the timestamp for sending events. The final timestamps is when the event can be heard from the speakers. If setTimestamp is false, then the event will be automatically set to the current time. Otherwise, the resulting time is the timestamp + sound latency * 2 (with timestamp being retrieved from GetTicks()). If the SunvoxChannel is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxChannel) SetLooping ¶
func (s *SunvoxChannel) SetLooping(loop bool) error
SetLooping sets whether the SunvoxChannel should loop.
If the SunvoxChannel is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxChannel) SetOnCurrentLineChange ¶
func (s *SunvoxChannel) SetOnCurrentLineChange(pollResolution time.Duration, onLinechange func(line int) bool)
SetOnCurrentLineChange sets a callback to be run on another goroutine that signals when the line changes. (Note that Sunvox's audio engine is going to be ahead of the callback by some time. Also note that when playing a song from beginning, the playhead goes to -1 momentarily.)
pollResolution is the resolution of the polling for the callback / amount of time slept between polls. If less than or equal to 0, it will be the default (10ms / 100 times per second). onLineChange is the callback to be called; if it returns false, the goroutine exits.
The goroutine will exit if the Channel closes or another callback is set. Setting onLineChange to nil will cancel any currently running callback.
func (*SunvoxChannel) SetOnPatternTouch ¶
func (s *SunvoxChannel) SetOnPatternTouch(pollResolution time.Duration, onPatternTouch func(p *SunvoxPattern, justStarted bool) bool)
SetOnPatternTouch sets a callback to be run on another goroutine when patterns are touched by the playhead during playback. (Note that Sunvox's audio engine is going to be ahead of the callback by some time. Also note that when playing a song from beginning, the playhead goes to -1 momentarily, so there will be a false execution of the callback on first run.)
pollResolution is the resolution of the polling for the callback / amount of time slept between polls. If less than or equal to 0, it will be the default (10ms / 100 times per second). onPatternTouch is the callback to be called with the SunvoxPattern that was touched. The callback must return a boolean value; if it returns false, the goroutine exits. justStarted indicates if the pattern is just starting to be played. If false, the pattern is just finishing being played.
The goroutine will exit if the Channel closes or another callback is set. Setting onPatternTouch to nil will cancel any currently running callback.
func (*SunvoxChannel) SetProjectFilename ¶
func (s *SunvoxChannel) SetProjectFilename(fname string)
SetProjectFilename sets the project's filename.
func (*SunvoxChannel) SetProjectName ¶
func (s *SunvoxChannel) SetProjectName(name string) error
SetProjectName sets the name for the project loaded in the channel. If there is an issue getting the song name, the function will return an error.
func (*SunvoxChannel) SetTPL ¶
func (c *SunvoxChannel) SetTPL(tpl int) error
SetTPL sets the TPL (ticks per line) for the project. The maximum value is 1F (31). If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxChannel) SetVolume ¶
func (s *SunvoxChannel) SetVolume(volume float32)
SetVolume sets the volume of the project loaded in the channel. Valid values range from 0 to 1. The fidelity is in 1/256 steps.
func (*SunvoxChannel) Stop ¶
func (s *SunvoxChannel) Stop() error
Stop stops / pauses audio playback that is currently playing back through the SunvoxChannel. If executed the second time, all continuing audio (like repeating echos or delays) is stopped, like in Sunvox.
If the SunvoxChannel is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
Note that functions that initiate or modify playback on a playing SunvoxChannel will be slow (on the order of ~50-100ms). If you do not need it immediately, it might be best to queue playback using one of the Queue* functions.
func (*SunvoxChannel) TPL ¶
func (c *SunvoxChannel) TPL() int
TPL returns the ticks per line for the song in the channel.
func (*SunvoxChannel) TPM ¶
func (c *SunvoxChannel) TPM() float32
TPM returns the number of ticks per minute of the project in the channel.
func (*SunvoxChannel) Unlock ¶
func (s *SunvoxChannel) Unlock() error
Unlocks the channel for simultaneous read/write from different threads / goroutines for the same channel. Some functions marked as "USE LOCK/UNLOCK" can't work without locking at all. If the SunvoxChannel is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxChannel) Volume ¶
func (s *SunvoxChannel) Volume() (float32, error)
Volume returns the current volume of the SunvoxChannel, ranging from 0 to 1.
type SunvoxEngine ¶
type SunvoxEngine struct { Initialized bool MajorVersion int MinorVersion int MinorVersion2 int // contains filtered or unexported fields }
SunvoxEngine represents the Sunvox music playback engine, and is mainly a collection of channels, into which projects can be instantiated or loaded and played back live.
func Engine ¶
func Engine() *SunvoxEngine
Engine returns the running Sunvox instance; each process can run only one.
func (*SunvoxEngine) ChannelByFilename ¶
func (e *SunvoxEngine) ChannelByFilename(filename string) *SunvoxChannel
IsPlayingFilename returns the Channel that has been loaded a project of the given filename.
func (*SunvoxEngine) ChannelByID ¶
func (e *SunvoxEngine) ChannelByID(id any, inUse ChannelInUseType) *SunvoxChannel
ChannelByID returns the first channel with the given ID. inUse indicates whether to only focus on channels that are in use or not, and what to do if channels with the desired usability cannot be found.
For example, ChannelAny is for any channel with the ID, ChannelInUse means the channel with the ID has to be in use, and ChannelInUseMaybe means the channel with the ID should be in use if possible; otherwise any channel with the ID would suffice.
func (*SunvoxEngine) ChannelByIndex ¶
func (e *SunvoxEngine) ChannelByIndex(index int) *SunvoxChannel
ChannelByIndex returns the channel with the given index, if it exists / has been created already. If no channel is found, ChannelByID returns nil.
func (*SunvoxEngine) CreateChannel ¶
func (e *SunvoxEngine) CreateChannel(id any) (*SunvoxChannel, error)
CreateChannel creates a SunvoxChannel and assigns it a custom ID to identify it. You may choose to assign unique IDs to each Channel. Note that a SunvoxEngine can only create 16 channels maximum.
func (*SunvoxEngine) Deinit ¶
func (e *SunvoxEngine) Deinit() error
Deinit deinitializes the Sunvox Engine. If for whatever reason that cannot be done, Deinit returns an error.
It seems like Deinit() doesn't really work properly at the moment, so it's best not to rely on it.
func (*SunvoxEngine) ForEachChannel ¶
func (e *SunvoxEngine) ForEachChannel(forEach func(channel *SunvoxChannel) bool)
ForEachChannel loops through each created SunvoxChannel in the engine.
func (*SunvoxEngine) Init ¶
func (e *SunvoxEngine) Init(libraryPath string, config *InitConfig) error
Init initializes the SunvoxEngine using the passed shared library filepath. The path is, by default, relative to the executable, in the current working directory. config is an InitConfig object that controls how the engine is initialized. The function automatically loads libraries using the OS and architecture hierarchy from the original DLL / library download.
func (*SunvoxEngine) InitFromDirectory ¶
func (e *SunvoxEngine) InitFromDirectory(libraryBaseDirectoryPath string, config *InitConfig) error
InitFromDirectory loads the SunvoxEngine using shared libraries in the base directory path given. The path is, by default, relative to the executable, in the current working directory. config is an InitConfig object that controls how the engine is initialized. The function automatically loads libraries using the OS and architecture folder hierarchy from the original DLL / library download.
func (*SunvoxEngine) SampleRate ¶
func (e *SunvoxEngine) SampleRate() (int, error)
SampleRate returns the sample rate of the engine.
func (*SunvoxEngine) Ticks ¶
func (s *SunvoxEngine) Ticks() uint32
Ticks returns the system ticks, used for setting the event timestamp.
func (*SunvoxEngine) TicksPerSecond ¶
func (s *SunvoxEngine) TicksPerSecond() uint32
TicksPerSecond returns the system ticks, used for setting the event timestamp.
type SunvoxModule ¶
type SunvoxModule struct { Channel *SunvoxChannel Index int }
SunvoxModule represents a module connected to other modules in a Sunvox project.
func (*SunvoxModule) Connect ¶
func (m *SunvoxModule) Connect(dest *SunvoxModule) error
Connect connects a Module to a specified other Module. If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxModule) ControllerMaximum ¶
func (m *SunvoxModule) ControllerMaximum(ctrlNum int) (int, error)
ControllerMaximum returns the maximum value in the range associated with the control index - for hexadecimal, you can precede the value with "0x". If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxModule) ControllerMinimum ¶
func (m *SunvoxModule) ControllerMinimum(ctrlNum int) (int, error)
ControllerMinimum returns the minimum value in the range associated with the control index - for hexadecimal, you can precede the value with "0x". If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxModule) ControllerName ¶
func (m *SunvoxModule) ControllerName(ctrlNum int) (string, error)
ControllerName returns the name associated with the control index - for hexadecimal, you can precede the value with "0x". If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxModule) ControllerValue ¶
func (m *SunvoxModule) ControllerValue(ctrlNum int) (int, error)
ControllerValue returns the value associated with the control index - for hexadecimal, you can precede the value with "0x". If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxModule) Disconnect ¶
func (m *SunvoxModule) Disconnect(dest *SunvoxModule) error
Disconnect disconnects a Module from a specified other Module. If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxModule) Finetune ¶
func (m *SunvoxModule) Finetune() uint32
Finetune returns the finetune value of the Module.
func (*SunvoxModule) Flags ¶
func (m *SunvoxModule) Flags() (int32, error)
Flags returns the flags set on the given module as a int32 flag set. If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxModule) IsValid ¶
func (m *SunvoxModule) IsValid() bool
IsValid returns if the SunvoxModule is valid / exists.
func (*SunvoxModule) Name ¶
func (m *SunvoxModule) Name() string
Name is the name of the module in the project.
func (*SunvoxModule) RelativeNote ¶
func (m *SunvoxModule) RelativeNote() uint32
RelativeNote returns the relative note value for the module.
func (*SunvoxModule) SetBSM ¶
func (m *SunvoxModule) SetBSM(bypass, solo, mute bool) error
Sets the bypass, solo, and mute values for the module. Note that this works only for instruments, not effects. If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxModule) SetControllerValue ¶
func (m *SunvoxModule) SetControllerValue(ctrlNum, value int) error
SetControlValue sets the numbered controller of ctrlNum to the value indicated. ctrlNum is the number of the controller as seen in Sunvox, not the indexed value (i.e. the first controller is 1 in Sunvox, so you would use 1 here, 1C in Sunvox is 0x1C here, etc). If ctrlNum is less than or equal to zero, SetControlValue returns an error. The value should be the logical value from Sunvox for the controller specified, not 0 - 8000. Controller #3 for an Analog Generator, panning, ranges from -128 to 128; to set this to 50% right would be: channel.ModuleByName("Analog generator").SetControlValue(3, 64)
func (*SunvoxModule) SetFinetune ¶
func (m *SunvoxModule) SetFinetune(finetune int) error
SetFinetune sets the finetune value for the module (with the default being 0). The value can range from -256 to 256. If the function is unable to execute for whatever reason, it will return an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxModule) SetRelativeNote ¶
func (m *SunvoxModule) SetRelativeNote(relativeNote int) error
SetRelativeNote sets the relative note value for the module (with the default being 0). If the function is unable to execute for whatever reason, it will return an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
type SunvoxPattern ¶
type SunvoxPattern struct { Channel *SunvoxChannel Index int }
SunvoxPattern represents a pattern in a Sunvox song.
func (*SunvoxPattern) CustomLooplessX ¶
func (p *SunvoxPattern) CustomLooplessX() int
CustomLooplessX returns the Line number (x-coordinate) of the pattern in Sunvox as if there was no custom loop set.
func (*SunvoxPattern) CustomLooplessX2 ¶
func (p *SunvoxPattern) CustomLooplessX2() int
CustomLooplessX2 returns the Line number (x-coordinate) of the end of the pattern in Sunvox as if there was no custom loop set.
func (*SunvoxPattern) Data ¶
func (p *SunvoxPattern) Data() (*SunvoxPatternData, error)
Data returns the data from the pattern for reading and modification. If the SunvoxPattern is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxPattern) IsValid ¶
func (p *SunvoxPattern) IsValid() bool
IsValid returns if the pattern exists (specifically, if the pattern has any lines).
func (*SunvoxPattern) LineCount ¶
func (p *SunvoxPattern) LineCount() (int, error)
LineCount returns the number of lines in the pattern. If the SunvoxPattern is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxPattern) Move ¶
func (p *SunvoxPattern) Move(dx, dy int) error
Move moves the pattern by the dx (with dx being in lines) and dy values specified. If the SunvoxPattern is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxPattern) Name ¶
func (p *SunvoxPattern) Name() string
Name returns the name of the given Pattern.
func (*SunvoxPattern) SetMute ¶
func (p *SunvoxPattern) SetMute(muted bool) (bool, error)
SetMute sets the pattern to be muted (or not). It returns whether the channel was previously muted or not, and an error if muting could not be done for whatever reason. If the SunvoxPattern is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxPattern) SetXY ¶
func (p *SunvoxPattern) SetXY(x, y int) error
SetXY sets the X (line position) and Y of the pattern to the given values. If the SunvoxPattern is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxPattern) TrackCount ¶
func (p *SunvoxPattern) TrackCount() (int, error)
TrackCount returns the number of tracks in the pattern. If the SunvoxPattern is unable to execute the function for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (*SunvoxPattern) X ¶
func (p *SunvoxPattern) X() int
X returns the Line number (x-coordinate) of the pattern in Sunvox.
func (*SunvoxPattern) X2 ¶
func (p *SunvoxPattern) X2() int
func (*SunvoxPattern) Y ¶
func (p *SunvoxPattern) Y() int
Y returns the Y coordinate of the pattern in Sunvox.
type SunvoxPatternData ¶
type SunvoxPatternData struct { Data []SunvoxPatternNoteData // contains filtered or unexported fields }
SunvoxPatternData represents note data for all lines for all tracks in a pattern's note data.
func (SunvoxPatternData) Controller ¶
func (s SunvoxPatternData) Controller(trackNum, lineNum int) (uint16, error)
Controller returns the specified controller index for the given note data for the track and line provided. If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (SunvoxPatternData) ControllerValue ¶
func (s SunvoxPatternData) ControllerValue(trackNum, lineNum int) (uint16, error)
ControllerValue returns the controller value (XXYY) for the given note data for the track and line provided. If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (SunvoxPatternData) LineCount ¶
func (s SunvoxPatternData) LineCount() int
LineCount returns the number of lines in the pattern data.
func (SunvoxPatternData) Module ¶
func (s SunvoxPatternData) Module(trackNum, lineNum int) (uint16, error)
Module returns the module number of the given note data for the track and line provided. If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (SunvoxPatternData) Note ¶
func (s SunvoxPatternData) Note(trackNum, lineNum int) (uint8, error)
Note returns the note of the track and line given, from hexadecimal. C5 is 61. If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (SunvoxPatternData) SetController ¶
func (s SunvoxPatternData) SetController(trackNum, lineNum int, controllerNumber uint16) error
SetController sets the specified controller index for the given note data for the track and line provided. If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (SunvoxPatternData) SetControllerValue ¶
func (s SunvoxPatternData) SetControllerValue(trackNum, lineNum int, value uint16) error
SetControllerValue sets the controller value (XXYY) for the given note data for the track and line provided. If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (SunvoxPatternData) SetModule ¶
func (s SunvoxPatternData) SetModule(trackNum, lineNum int, moduleNumber uint16) error
SetModule sets the module number of the given note data to the value given. If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (SunvoxPatternData) SetNote ¶
func (s SunvoxPatternData) SetNote(trackNum, lineNum int, noteValue uint8) error
SetNote sets the note for the given note data to the value specified. You can use the NoteCommand constants for special note types. C5 is 61. If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (SunvoxPatternData) SetVelocity ¶
func (s SunvoxPatternData) SetVelocity(trackNum, lineNum int, velocity uint8) error
SetVelocity sets the velocity of the given note data, ranging from 0-129 (with 0 being the default volume level). If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
func (SunvoxPatternData) TrackCount ¶
func (s SunvoxPatternData) TrackCount() int
TrackCount returns the number of tracks in the pattern data.
func (SunvoxPatternData) Velocity ¶
func (s SunvoxPatternData) Velocity(trackNum, lineNum int) (uint8, error)
Velocity returns the velocity of the given note data, ranging from 0-129 (with 0 being the default volume level). If the function is unable to execute for whatever reason, the function returns an error code (and, if the SunvoxEngine is initialized in debug mode (which is the default), the engine will print exactly what the error might be).
type SunvoxPatternNoteData ¶
type SunvoxPatternNoteData struct { Note uint8 Velocity uint8 Module uint16 Controller uint16 ControllerValue uint16 }
SunvoxPatternNoteData represents note data for one line for one track in a pattern's note data.
type VolumeFade ¶
type VolumeFade struct { Channel *SunvoxChannel // contains filtered or unexported fields }
func NewVolumeFade ¶
func NewVolumeFade(start, end, seconds float32, channel *SunvoxChannel) *VolumeFade
func (*VolumeFade) Restart ¶
func (f *VolumeFade) Restart()