module

SunVox

Constants

BUFFER_SIZE = 1024
CURRENT_VERSION_MAJOR = 2
CURRENT_VERSION_MINOR = 1
CURRENT_VERSION_MINOR2 = 4
DEFAULT_CHANNELS = 2
DEFAULT_CONFIG = ""
DEFAULT_FREQ = 44100
MAX_SLOTS = 16
NO_MODULE = -1
OUTPUT_MODULE = 0

Class methods

audio_callback(buf : Bytes | Slice(Int16) | Slice(Float32), frames : Int32, latency : Int32 = 0, out_time : UInt32 = ticks) : Int32

Gets the next piece of SunVox audio from the Output module (requires offline: true).

Source
audio_callback2(out_buf : Bytes | Slice(Int16) | Slice(Float32), frames : Int32, in_buf : Bytes | Slice(Int16) | Slice(Float32), in_type : SampleType = SampleType::Int16, in_channels : Int32 = DEFAULT_CHANNELS, latency : Int32 = 0, out_time : UInt32 = ticks) : Int32

Sends audio to the Input module and receives filtered audio from the Output module (requires offline: true).

Source
autostop?(slot : Slot | Int32) : Bool

Returns true if autostop is enabled on slot.

Source
close_slot(slot : Slot | Int32) : Nil

Closes a slot. Raises exception if the slot is closed or something goes wrong.

Source
connect_module(slot : Slot | Int32, src : Module | Int32, dest : Module | Int32) : Bool

Connect a module src to a module dest.

Source
disconnect_module(slot : Slot | Int32, src : Module | Int32, dest : Module | Int32) : Bool

Disconnect a module src from a module dest.

Source
end_of_song?(slot : Slot | Int32) : Bool

Is the song over and the end has been reached?

Source
engine_version
Source
export_to_wav(slot : Slot | Int32, song_len_frames : Int, out_filename : String | Path)
Source
find_module(slot : Slot | Int32, name : String) : Int32

Find a module in a slot by name (returns -1 if not found).

Source
find_pattern(slot : Slot | Int32, name : String) : Int32

Finds the pattern in slot by name (returns -1 if not found).

Source
frequency_to_pitch(in_freq)
Source
get_base_version(slot : Slot | Int32)

Gets the SunVox version used to create the project in slot.

Source
get_current_line(slot : Slot | Int32)

The current line the playhead is at.

Source
get_current_line2(slot : Slot | Int32)

The current line the playhead is at in fixed-point 27.5 format.

Source
get_current_signal_level(slot : Slot | Int32, channel : Int32 = 0) : Int32

Gets the current output signal level (0..255).

Source
get_log(bytes : Int32 = 4096) : String

Gets the debug log messages.

Source
get_module_color(slot : Slot | Int32, module_num : Module | Int32) : Int32

Get the color of a module in 0xBBGGRR format.

Source
get_module_ctl_group(slot : Slot | Int32, module_num : Module | Int32, ctl_num : Int32) : Int32

Get the group number of a module's controller.

Source
get_module_ctl_max(slot : Slot | Int32, module_num : Module | Int32, ctl_num : Int32, scaled : Bool | CtlScale | Int32 = false) : Int32

Get the maximum value of a module's controller.

Source
get_module_ctl_min(slot : Slot | Int32, module_num : Module | Int32, ctl_num : Int32, scaled : Bool | CtlScale | Int32 = false) : Int32

Get the minimum value of a module's controller.

Source
get_module_ctl_name(slot : Slot | Int32, module_num : Module | Int32, ctl_num : Int32) : String

Get the name of a module's controller.

Source
get_module_ctl_offset(slot : Slot | Int32, module_num : Module | Int32, ctl_num : Int32) : Int32

Get the display value offset of a module's controller.

Source
get_module_ctl_type(slot : Slot | Int32, module_num : Module | Int32, ctl_num : Int32) : CtlType

Get the type of a module's controller (CtlType::Normal or CtlType::Selector).

Source
get_module_ctl_value(slot : Slot | Int32, module_num : Module | Int32, ctl_num : Int32, scaled : Bool | CtlScale | Int32 = false) : Int32

Get the value of a module's controller (scaled can be a Bool, CtlScale, or 0..2).

Source
get_module_curve(slot : Slot | Int32, module_num : Module | Int32, curve_num : Int32, length : Int32 = 257) : Slice(Float32)

Get the curve data (Slice(Float32)) from a module.

Source
get_module_finetune(slot : Slot | Int32, module_num : Module | Int32) : NamedTuple(finetune: Int32, relative_note: Int32)

Get module's {finetune, relative_note} values.

Source
get_module_flags(slot : Slot | Int32, module_num : Module | Int32) : UInt32

Get the flags set on a module.

Source
get_module_inputs(slot : Slot | Int32, module_num : Module | Int32) : Slice(Int32)

A slice of all input link slots a module has (entries may be -1 if unconnected).

Source
get_module_inputs_number(slot : Slot | Int32, module_num : Module | Int32) : Int32

The number of module input link slots.

Source
get_module_name(slot : Slot | Int32, module_num : Module | Int32) : String

Gets the name of a module.

Source
get_module_outputs(slot : Slot | Int32, module_num : Module | Int32) : Slice(Int32)

A slice of all output link slots a module has (entries may be -1 if unconnected).

Source
get_module_outputs_number(slot : Slot | Int32, module_num : Module | Int32) : Int32

The number of module output link slots.

Source
get_module_scope(slot : Slot | Int32, module_num : Module | Int32, channel : Int32 = 0, samples_to_read : Int32 = 1024) : Slice(Int16)

Get the raw audio output scope values (Slice(Int16)) for a module.

Source
get_module_type(slot : Slot | Int32, module_num : Module | Int32) : String

Gets the type string of a module (e.g. "Generator", "Filter Pro", "Output").

Source
get_module_xy(slot : Slot | Int32, module_num : Module | Int32) : NamedTuple(x: Int32, y: Int32)

Get the {x, y} position of a module.

Source
get_number_of_module_ctls(slot : Slot | Int32, module_num : Module | Int32) : Int32

Get the number of controllers a module has.

Source
get_number_of_modules(slot : Slot | Int32)

The number of module slots in slot.

Source
get_number_of_patterns(slot : Slot | Int32)

Gets the number of pattern slots in slot.

Source
get_pattern_data(slot : Slot | Int32, pattern_num : Pattern | Int32) : Array(Array(SunVox::Event))

Get the event data, separated by tracks (Array(Array(SunVox::Event))).

Source
get_pattern_event(slot : Slot | Int32, pat_num : Pattern | Int32, track : Int32, line : Int32, column : PatternColumn | Int32) : Int32

Reads a field (column) from the pattern event at (track, line).

Source
get_pattern_lines(slot : Slot | Int32, pattern_num : Pattern | Int32) : Int32

Gets the number of lines in a pattern.

Source
get_pattern_name(slot : Slot | Int32, pattern_num : Pattern | Int32) : String

Gets the pattern's name.

Source
get_pattern_tracks(slot : Slot | Int32, pattern_num : Pattern | Int32) : Int32

Gets the number of tracks in a pattern.

Source
get_pattern_x(slot : Slot | Int32, pat_num : Pattern | Int32) : Int32

Gets the pattern's starting line (X coordinate on timeline).

Source
get_pattern_y(slot : Slot | Int32, pat_num : Pattern | Int32) : Int32

Gets the pattern's vertical position (Y coordinate on timeline).

Source
get_raw_pattern_data(slot : Slot | Int32, pattern_num : Pattern | Int32) : Slice(LibSunVox::Event)

Returns the raw mutable pattern buffer (Slice(LibSunVox::Event)).

Source
get_sampler_par(slot : Slot | Int32, sampler_module_num : Module | Int32, sample_slot : Int32, par : SamplerParam | Int32) : Int32

Gets a sample parameter from a Sampler module.

Source
get_song_bpm(slot : Slot | Int32)

Gets the BPM of the song in slot.

Source
get_song_length(slot : Slot | Int32) : Time::Span

Get the length of the song in seconds as a Time::Span.

Source
get_song_length_frames(slot : Slot | Int32)

The total length in frames of the song in slot.

Source
get_song_length_lines(slot : Slot | Int32)

The total song length in lines of slot.

Source
get_song_name(slot : Slot | Int32) : String

Gets the name of the song in slot.

Source
get_song_tpl(slot : Slot | Int32)

Gets the TPL (Ticks Per Line) of the song in slot.

Source
get_volume(slot : Slot | Int32) : Int32

Queries the current volume of slot (0..256).

Source
load(slot : Slot | Int32, filename : String | Path) : Nil

Loads a project file from disk into a slot.

Source
load_from_memory(slot : Slot | Int32, data : Bytes) : Nil

Loads a project from a memory buffer (Bytes) into a slot.

Source
load_module(slot : Slot | Int32, filename : String | Path, x = 512, y = 512, z = 0) : Int32

Load a module from a file (sunsynth, xi, wav, aiff, ogg, mp3, flac).

Source
load_module_from_memory(slot : Slot | Int32, data : Bytes, x = 512, y = 512, z = 0) : Int32

Load a module or sample from a memory block (Bytes).

Source
lock_slot(slot : Slot | Int32) : Nil

Locks the slot for thread-safe modification.

Source
metamodule_load(slot : Slot | Int32, module_num : Module | Int32, filename : String | Path) : Nil

Loads a file (sunvox, mod, xm, midi) into a MetaModule.

Source
metamodule_load_from_memory(slot : Slot | Int32, module_num : Module | Int32, data : Bytes) : Nil

Loads a file from memory (Bytes) into a MetaModule.

Source
module_bypass?(slot : Slot | Int32, module_num : Module | Int32) : Bool
Source
module_effect?(slot : Slot | Int32, module_num : Module | Int32) : Bool
Source
module_exists?(slot : Slot | Int32, module_num : Module | Int32) : Bool
Source
module_generator?(slot : Slot | Int32, module_num : Module | Int32) : Bool
Source
module_mute?(slot : Slot | Int32, module_num : Module | Int32) : Bool
Source
module_solo?(slot : Slot | Int32, module_num : Module | Int32) : Bool
Source
new_module(slot : Slot | Int32, type : ModuleType | String, name = "", x = 512, y = 512, z = 0) : Int32

Create a new module in slot. Returns the number of the new module.

Source
new_pattern(slot : Slot | Int32, clone : Pattern | Int32 = -1, x : Int32 = 0, y : Int32 = 0, tracks : Int32 = 4, lines : Int32 = 32, icon_seed : Int32 = 0, name : String = "") : Int32

Creates a new pattern in slot. Returns the pattern number.

Source
offline?
Source
open_slot(slot : Slot | Int32 = Slot::Zero) : Slot

Opens a slot (defaults to Slot::Zero) and returns the Slot.

Source
open_slot(slot : Slot | Int32 = Slot::Zero, & : Slot -> )

Opens a slot for the duration of the block and ensures it is closed afterwards.

Source
open_slots

Returns an array of all currently open Slots.

Source
pattern_mute(slot : Slot | Int32, pattern_num : Pattern | Int32, mute : Bool = true) : Bool

Mute/Unmute the pattern. Returns the previous mute state (true if previously muted).

Source
pattern_muted?(slot : Slot | Int32, pattern_num : Pattern | Int32) : Bool

Queries whether pattern_num is currently muted without changing its state.

Source
pause(slot : Slot | Int32)

Pauses the playback at the current line.

Source
pitch_to_frequency(in_pitch)
Source
play(slot : Slot | Int32)

Plays the current song from the current line.

Source
play_from_beginning(slot : Slot | Int32)

Plays the current song from the beginning (line 0).

Source
remove_module(slot : Slot | Int32, module_num : Module | Int32) : Bool

Remove the module module_num in slot.

Source
remove_pattern(slot : Slot | Int32, pat_num : Pattern | Int32) : Bool

Removes a pattern in slot.

Source
repeats?(slot : Slot | Int32) : Bool

Returns whether or not autostop is set (preserved for backwards compatibility).

Source
resume(slot : Slot | Int32)

Resumes playback from a paused state.

Source
rewind(slot : Slot | Int32, line_num : Int32)

Alias for skip_to_line.

Source
sample_rate
Source
sample_size
Source
sampler_load(slot : Slot | Int32, sampler_module_num : Module | Int32, filename : String | Path, sample_slot = -1) : Nil

Loads a file into a Sampler (xi, wav, aiff, ogg, mp3, flac).

Source
sampler_load_from_memory(slot : Slot | Int32, sampler_module_num : Module | Int32, data : Bytes, sample_slot = -1) : Nil

Loads a sample from memory (Bytes) into a Sampler module.

Source
sampler_par(slot : Slot | Int32, sampler_module_num : Module | Int32, sample_slot : Int32, par : SamplerParam | Int32, par_val : Int32 = 0, set : Bool = false) : Int32

Gets or sets a sample parameter on a Sampler module (sv_sampler_par).

Source
save(slot : Slot | Int32, filename : String | Path) : Nil

Saves the project in slot to a file on disk.

Source
save_to_memory(slot : Slot | Int32) : Bytes

Saves the project in slot to a newly allocated Bytes slice in memory.

Source
send_event(slot : Slot | Int32, track_num : Int32, note : Note, velocity : Int, module_num : Module | Int = -1, ctl : Int = 0, effect : Int = 0, ctl_value : Int = 0)

Sends an event to SunVox. Can be used to send notes, change ctl values, or set note effects.

Source
send_event(slot : Slot | Int32, track_num : Int32, note : Int32, velocity : Int, module_num : Module | Int = -1, ctl : Int = 0, effect : Int = 0, ctl_value : Int = 0)

Sends an event to SunVox. Can be used to send notes, change ctl values, or set note effects.

Source
send_event(slot : Slot | Int32, track_num : Int32, event : Event)

Sends an Event record to SunVox on track_num.

Source
set_autostop(slot : Slot | Int32, autostop : Bool) : Nil

Enables or disables autostop on slot.

Source
set_event_time(slot : Slot | Int32, timestamp : UInt32 = 0_u32, set = true)

Sets the timestamp of events to be sent by send_event.

Source
set_module_color(slot : Slot | Int32, module_num : Module | Int32, color : Int32) : Nil

Set the color of a module in 0xBBGGRR format.

Source
set_module_ctl_value(slot : Slot | Int32, module_num : Module | Int32, ctl_num : Int32, val : Int32, scaled : Bool | CtlScale | Int32 = false) : Nil

Set the value of a module's controller (sv_set_module_ctl_value).

Source
set_module_curve(slot : Slot | Int32, module_num : Module | Int32, curve_num : Int32, curve_data : Slice(Float32)) : Int32

Set the curve data of a module. Returns the number of items written.

Source
set_module_finetune(slot : Slot | Int32, module_num : Module | Int32, finetune : Int32) : Nil

Set the module's finetune (-256..256) immediately.

Source
set_module_name(slot : Slot | Int32, module_num : Module | Int32, name : String) : Nil

Sets the name of a module.

Source
set_module_relnote(slot : Slot | Int32, module_num : Module | Int32, relative_note : Int32) : Nil

Set the module's relative note (transposition) immediately.

Source
set_module_xy(slot : Slot | Int32, module_num : Module | Int32, x : Int32, y : Int32) : Nil

Set the (x, y) position of a module.

Source
set_pattern_event(slot : Slot | Int32, pat_num : Pattern | Int32, track : Int32, line : Int32, nn : Int32 = -1, vv : Int32 = -1, mm : Int32 = -1, ccee : Int32 = -1, xxyy : Int32 = -1) : Nil

Writes a pattern event to the cell at (track, line). Negative field values are ignored (left unchanged).

Source
set_pattern_name(slot : Slot | Int32, pattern_num : Pattern | Int32, name : String) : Bool

Sets the pattern's name.

Source
set_pattern_size(slot : Slot | Int32, pattern_num : Pattern | Int32, tracks : Int32 = -1, lines : Int32 = -1) : Bool

Sets the number of tracks and/or lines of a pattern (-1 leaves unchanged).

Source
set_pattern_xy(slot : Slot | Int32, pat_num : Pattern | Int32, x : Int32, y : Int32) : Bool

Sets the pattern's (x, y) coordinates on the timeline.

Source
set_repeat(slot : Slot | Int32, bool : Bool) : Nil

Sets autostop flag (preserved for backwards compatibility).

Source
set_sampler_par(slot : Slot | Int32, sampler_module_num : Module | Int32, sample_slot : Int32, par : SamplerParam | Int32, val : Int32) : Int32

Sets a sample parameter on a Sampler module and returns the previous value.

Source
set_song_name(slot : Slot | Int32, name : String) : Nil

Sets the name of the song in slot.

Source
skip_to_line(slot : Slot | Int32, line_num : Int32)

Jumps the current position of the playhead to a line number.

Source
slot_open?(slot : Slot | Int32) : Bool

Returns true if slot is currently open.

Source
start_engine(config = DEFAULT_CONFIG, freq = DEFAULT_FREQ, channels = DEFAULT_CHANNELS, no_debug_output = false, offline = false, sample_type = SampleType::Int16, one_thread = false)

Starts up the SunVox Engine. Hooks at_exit to ensure stop_engine is run on close.

Source
start_engine(config = DEFAULT_CONFIG, freq = DEFAULT_FREQ, channels = DEFAULT_CHANNELS, no_debug_output = false, offline = false, sample_type = SampleType::Int16, one_thread = false, &)

Starts the SunVox Engine for the duration of the block and ensures stop_engine is called afterwards.

Source
started?
Source
stop(slot : Slot | Int32)

Stops the current song from playing. 2 calls will stop all the synths and sounds.

Source
stop_engine

Shuts down the engine and closes all open slots.

Source
sync_resume(slot : Slot | Int32)

Waits for sync (pattern effect 0x33 on any slot) and resumes the audio stream on slot.

Source
ticks

The current system tick.

Source
ticks_per_second

How many system ticks happen per second.

Source
time_map(slot : Slot | Int32, start_line : Int32, len : Int32, flags : TimeMapFlags | Int32 = TimeMapFlags::Speed) : Slice(UInt32)

Gets the project time map for len lines starting at start_line.

Source
unlock_slot(slot : Slot | Int32) : Nil

Unlocks the slot after modification.

Source
update_input
Source
version_string

Formatted version string of the active SunVox engine (e.g. "2.1.4").

Source
volume(slot : Slot | Int32, volume : Int) : Int32

Sets the output volume of the slot (0..256). Negative values query current volume without changing it.

Source
vplayer_load(slot : Slot | Int32, module_num : Module | Int32, filename : String | Path) : Nil

Loads an OGG file into a Vorbis Player module.

Source
vplayer_load_from_memory(slot : Slot | Int32, module_num : Module | Int32, data : Bytes) : Nil

Loads an OGG file from memory (Bytes) into a Vorbis Player module.

Source

Nested types