module SunVox

Defined in:

module.cr
note.cr
pattern.cr
slot.cr
sunvox.cr

Constant Summary

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 Method Summary

Class Method Detail

def self.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).


[View source]
def self.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).


[View source]
def self.autostop?(slot : Slot | Int32) : Bool #

Returns true if autostop is enabled on slot.


[View source]
def self.close_slot(slot : Slot | Int32) : Nil #

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


[View source]
def self.connect_module(slot : Slot | Int32, src : Module | Int32, dest : Module | Int32) : Bool #

Connect a module src to a module dest.


[View source]
def self.disconnect_module(slot : Slot | Int32, src : Module | Int32, dest : Module | Int32) : Bool #

Disconnect a module src from a module dest.


[View source]
def self.end_of_song?(slot : Slot | Int32) : Bool #

Is the song over and the end has been reached?


[View source]
def self.engine_version #

[View source]
def self.export_to_wav(slot : Slot | Int32, song_len_frames : Int, out_filename : String | Path) #

[View source]
def self.find_module(slot : Slot | Int32, name : String) : Int32 #

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


[View source]
def self.find_pattern(slot : Slot | Int32, name : String) : Int32 #

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


[View source]
def self.frequency_to_pitch(in_freq) #

[View source]
def self.get_base_version(slot : Slot | Int32) #

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


[View source]
def self.get_current_line(slot : Slot | Int32) #

The current line the playhead is at.


[View source]
def self.get_current_line2(slot : Slot | Int32) #

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


[View source]
def self.get_current_signal_level(slot : Slot | Int32, channel : Int32 = 0) : Int32 #

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


[View source]
def self.get_log(bytes : Int32 = 4096) : String #

Gets the debug log messages.


[View source]
def self.get_module_color(slot : Slot | Int32, module_num : Module | Int32) : Int32 #

Get the color of a module in 0xBBGGRR format.


[View source]
def self.get_module_ctl_group(slot : Slot | Int32, module_num : Module | Int32, ctl_num : Int32) : Int32 #

Get the group number of a module's controller.


[View source]
def self.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.


[View source]
def self.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.


[View source]
def self.get_module_ctl_name(slot : Slot | Int32, module_num : Module | Int32, ctl_num : Int32) : String #

Get the name of a module's controller.


[View source]
def self.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.


[View source]
def self.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).


[View source]
def self.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).


[View source]
def self.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.


[View source]
def self.get_module_finetune(slot : Slot | Int32, module_num : Module | Int32) : NamedTuple(finetune: Int32, relative_note: Int32) #

Get module's {finetune, relative_note} values.


[View source]
def self.get_module_flags(slot : Slot | Int32, module_num : Module | Int32) : UInt32 #

Get the flags set on a module.


[View source]
def self.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).


[View source]
def self.get_module_inputs_number(slot : Slot | Int32, module_num : Module | Int32) : Int32 #

The number of module input link slots.


[View source]
def self.get_module_name(slot : Slot | Int32, module_num : Module | Int32) : String #

Gets the name of a module.


[View source]
def self.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).


[View source]
def self.get_module_outputs_number(slot : Slot | Int32, module_num : Module | Int32) : Int32 #

The number of module output link slots.


[View source]
def self.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.


[View source]
def self.get_module_type(slot : Slot | Int32, module_num : Module | Int32) : String #

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


[View source]
def self.get_module_xy(slot : Slot | Int32, module_num : Module | Int32) : NamedTuple(x: Int32, y: Int32) #

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


[View source]
def self.get_number_of_module_ctls(slot : Slot | Int32, module_num : Module | Int32) : Int32 #

Get the number of controllers a module has.


[View source]
def self.get_number_of_modules(slot : Slot | Int32) #

The number of module slots in slot.


[View source]
def self.get_number_of_patterns(slot : Slot | Int32) #

Gets the number of pattern slots in slot.


[View source]
def self.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))).


[View source]
def self.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).


[View source]
def self.get_pattern_lines(slot : Slot | Int32, pattern_num : Pattern | Int32) : Int32 #

Gets the number of lines in a pattern.


[View source]
def self.get_pattern_name(slot : Slot | Int32, pattern_num : Pattern | Int32) : String #

Gets the pattern's name.


[View source]
def self.get_pattern_tracks(slot : Slot | Int32, pattern_num : Pattern | Int32) : Int32 #

Gets the number of tracks in a pattern.


[View source]
def self.get_pattern_x(slot : Slot | Int32, pat_num : Pattern | Int32) : Int32 #

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


[View source]
def self.get_pattern_y(slot : Slot | Int32, pat_num : Pattern | Int32) : Int32 #

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


[View source]
def self.get_raw_pattern_data(slot : Slot | Int32, pattern_num : Pattern | Int32) : Slice(LibSunVox::Event) #

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


[View source]
def self.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.


[View source]
def self.get_song_bpm(slot : Slot | Int32) #

Gets the BPM of the song in slot.


[View source]
def self.get_song_length(slot : Slot | Int32) : Time::Span #

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


[View source]
def self.get_song_length_frames(slot : Slot | Int32) #

The total length in frames of the song in slot.


[View source]
def self.get_song_length_lines(slot : Slot | Int32) #

The total song length in lines of slot.


[View source]
def self.get_song_name(slot : Slot | Int32) : String #

Gets the name of the song in slot.


[View source]
def self.get_song_tpl(slot : Slot | Int32) #

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


[View source]
def self.get_volume(slot : Slot | Int32) : Int32 #

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


[View source]
def self.load(slot : Slot | Int32, filename : String | Path) : Nil #

Loads a project file from disk into a slot.


[View source]
def self.load_from_memory(slot : Slot | Int32, data : Bytes) : Nil #

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


[View source]
def self.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).


[View source]
def self.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).


[View source]
def self.lock_slot(slot : Slot | Int32) : Nil #

Locks the slot for thread-safe modification.


[View source]
def self.metamodule_load(slot : Slot | Int32, module_num : Module | Int32, filename : String | Path) : Nil #

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


[View source]
def self.metamodule_load_from_memory(slot : Slot | Int32, module_num : Module | Int32, data : Bytes) : Nil #

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


[View source]
def self.module_bypass?(slot : Slot | Int32, module_num : Module | Int32) : Bool #

[View source]
def self.module_effect?(slot : Slot | Int32, module_num : Module | Int32) : Bool #

[View source]
def self.module_exists?(slot : Slot | Int32, module_num : Module | Int32) : Bool #

[View source]
def self.module_generator?(slot : Slot | Int32, module_num : Module | Int32) : Bool #

[View source]
def self.module_mute?(slot : Slot | Int32, module_num : Module | Int32) : Bool #

[View source]
def self.module_solo?(slot : Slot | Int32, module_num : Module | Int32) : Bool #

[View source]
def self.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.


[View source]
def self.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.


[View source]
def self.offline? #

[View source]
def self.open_slot(slot : Slot | Int32 = Slot::Zero) : Slot #

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


[View source]
def self.open_slot(slot : Slot | Int32 = Slot::Zero, & : Slot -> ) #

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


[View source]
def self.open_slots : Array(Slot) #

Returns an array of all currently open Slots.


[View source]
def self.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).


[View source]
def self.pattern_muted?(slot : Slot | Int32, pattern_num : Pattern | Int32) : Bool #

Queries whether pattern_num is currently muted without changing its state.


[View source]
def self.pause(slot : Slot | Int32) #

Pauses the playback at the current line.


[View source]
def self.pitch_to_frequency(in_pitch) #

[View source]
def self.play(slot : Slot | Int32) #

Plays the current song from the current line.


[View source]
def self.play_from_beginning(slot : Slot | Int32) #

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


[View source]
def self.remove_module(slot : Slot | Int32, module_num : Module | Int32) : Bool #

Remove the module module_num in slot.


[View source]
def self.remove_pattern(slot : Slot | Int32, pat_num : Pattern | Int32) : Bool #

Removes a pattern in slot.


[View source]
def self.repeats?(slot : Slot | Int32) : Bool #

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


[View source]
def self.resume(slot : Slot | Int32) #

Resumes playback from a paused state.


[View source]
def self.rewind(slot : Slot | Int32, line_num : Int32) #

Alias for .skip_to_line.


[View source]
def self.sample_rate #

[View source]
def self.sample_size #

[View source]
def self.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).


[View source]
def self.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.


[View source]
def self.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).


[View source]
def self.save(slot : Slot | Int32, filename : String | Path) : Nil #

Saves the project in slot to a file on disk.


[View source]
def self.save_to_memory(slot : Slot | Int32) : Bytes #

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


[View source]
def self.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.


[View source]
def self.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.


[View source]
def self.send_event(slot : Slot | Int32, track_num : Int32, event : Event) #

Sends an Event record to SunVox on track_num.


[View source]
def self.set_autostop(slot : Slot | Int32, autostop : Bool) : Nil #

Enables or disables autostop on slot.


[View source]
def self.set_event_time(slot : Slot | Int32, timestamp : UInt32 = 0_u32, set = true) #

Sets the timestamp of events to be sent by .send_event.


[View source]
def self.set_module_color(slot : Slot | Int32, module_num : Module | Int32, color : Int32) : Nil #

Set the color of a module in 0xBBGGRR format.


[View source]
def self.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).


[View source]
def self.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.


[View source]
def self.set_module_finetune(slot : Slot | Int32, module_num : Module | Int32, finetune : Int32) : Nil #

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


[View source]
def self.set_module_name(slot : Slot | Int32, module_num : Module | Int32, name : String) : Nil #

Sets the name of a module.


[View source]
def self.set_module_relnote(slot : Slot | Int32, module_num : Module | Int32, relative_note : Int32) : Nil #

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


[View source]
def self.set_module_xy(slot : Slot | Int32, module_num : Module | Int32, x : Int32, y : Int32) : Nil #

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


[View source]
def self.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).


[View source]
def self.set_pattern_name(slot : Slot | Int32, pattern_num : Pattern | Int32, name : String) : Bool #

Sets the pattern's name.


[View source]
def self.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).


[View source]
def self.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.


[View source]
def self.set_repeat(slot : Slot | Int32, bool : Bool) : Nil #

Sets autostop flag (preserved for backwards compatibility).


[View source]
def self.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.


[View source]
def self.set_song_name(slot : Slot | Int32, name : String) : Nil #

Sets the name of the song in slot.


[View source]
def self.skip_to_line(slot : Slot | Int32, line_num : Int32) #

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


[View source]
def self.slot_open?(slot : Slot | Int32) : Bool #

Returns true if slot is currently open.


[View source]
def self.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.


[View source]
def self.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.


[View source]
def self.started? #

[View source]
def self.stop(slot : Slot | Int32) #

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


[View source]
def self.stop_engine #

Shuts down the engine and closes all open slots.


[View source]
def self.sync_resume(slot : Slot | Int32) #

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


[View source]
def self.ticks : UInt32 #

The current system tick.


[View source]
def self.ticks_per_second : UInt32 #

How many system ticks happen per second.


[View source]
def self.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.


[View source]
def self.unlock_slot(slot : Slot | Int32) : Nil #

Unlocks the slot after modification.


[View source]
def self.update_input #

[View source]
def self.version_string : String #

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


[View source]
def self.volume(slot : Slot | Int32, volume : Int) : Int32 #

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


[View source]
def self.vplayer_load(slot : Slot | Int32, module_num : Module | Int32, filename : String | Path) : Nil #

Loads an OGG file into a Vorbis Player module.


[View source]
def self.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.


[View source]