You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
189 lines
4.4 KiB
189 lines
4.4 KiB
// sunvox multitrack importer |
|
// by acheney |
|
// under mit license |
|
|
|
// - CONFIG BEGIN - |
|
|
|
// -- TIME CONFIG -- |
|
|
|
// the bpm of the project (affects granulation + length) |
|
bpm = 125 |
|
|
|
// the tpl of the project (affects granulation + length) |
|
tpl = 6 |
|
|
|
// -- GRANULATION CONFIG -- |
|
|
|
// granulate the samples across the pattern. |
|
// to adjust the granulation's envelope, load, edit, and then save the "envelope-sampler" sunsynth. |
|
//the upside is that you can slice and restart the patterns anywhere and the sample will play at that position. you can also timestretch them by adjusting the project speed |
|
//the downside is that depending on the speed of the project and the envelope of the sampler the granulation will sound either phaser-y or waver-y depending on the envelope length and project speed |
|
granulate = 0 |
|
|
|
// polyphony of the granulation |
|
gran_poly = 4 |
|
|
|
// volume of the granulated samples |
|
gran_vol = 256 |
|
|
|
// granulation envelope length |
|
// gran_len = 128 |
|
|
|
// -- MISC CONFIG -- |
|
|
|
// connect all sampler modules to the output |
|
out_connect = 1 |
|
|
|
// file format mask (wav, flac, ogg, mp3) |
|
mask = "wav" |
|
|
|
// - END CONFIG - |
|
|
|
// init variables |
|
path = CURRENT_PATH |
|
|
|
fl = new_flist( path, mask ) |
|
sv = sv_new() |
|
sv_load( sv, "template.sunvox" ) |
|
|
|
fcount = 0 |
|
|
|
// main |
|
|
|
sv_set_event_t( sv, 1, 0 ) |
|
|
|
sv_send_event( sv, 0, 0, 0, 0, 0x000F, tpl ) |
|
sv_send_event( sv, 0, 0, 0, 0, 0x001F, bpm ) |
|
|
|
if fl >= 0 |
|
{ |
|
|
|
while( 1 ) |
|
{ |
|
|
|
fname = get_flist_name( fl ) |
|
ftype = get_flist_type( fl ) |
|
|
|
if ftype == 0 |
|
{ |
|
|
|
sv_lock( sv ) |
|
|
|
if granulate |
|
{ |
|
|
|
sv_load_module( sv, "envelope-sampler.sunsynth", 448, ( fcount * -128 ) + 512, 0 ) |
|
sv_set_module_name( sv, fcount + 1, fname ) |
|
|
|
sv_set_module_ctl_value( sv, fcount + 1, 0, gran_vol, 0 ) |
|
sv_set_module_ctl_value( sv, fcount + 1, 4, gran_poly, 0 ) |
|
// sv_set_module_ctl_value( sv, fcount + 1, 6, gran_len, 0 ) |
|
|
|
|
|
} else { |
|
|
|
sv_new_module( sv, "Sampler", fname, 448 , ( fcount * -128 ) + 512, 0 ) |
|
|
|
sv_set_module_ctl_value( sv, fcount + 1, 0, 512, 2 ) |
|
sv_set_module_ctl_value( sv, fcount + 1, 4, 1, 2 ) |
|
|
|
} |
|
|
|
|
|
|
|
if out_connect |
|
{ |
|
|
|
sv_connect_module( sv, fcount + 1, 0 ) |
|
|
|
} |
|
|
|
pat_len = get_track_pattern_length( fname, bpm, tpl, mul ) |
|
pat = sv_new_pattern( sv, -1, 0, ( ( fcount * 32 ) + 64 ), 1, pat_len, fcount, fname ) |
|
|
|
if granulate |
|
{ |
|
for( i = 0; i < pat_len; i + 1 ) |
|
{ |
|
|
|
sv_set_pattern_event( sv, pat, 0, i, 61, 129, fcount + 2, 0007, ( 32768 / pat_len ) * i ) |
|
|
|
} |
|
|
|
} else { |
|
|
|
sv_set_pattern_event( sv, pat, 0, i, 61, 129, fcount + 2, 0000, 0000 ) |
|
|
|
} |
|
|
|
sv_unlock( sv ) |
|
|
|
sv_sampler_load( sv, fcount + 1, fname, 0 ) |
|
|
|
fcount = fcount + 1 |
|
|
|
} |
|
|
|
if flist_next( fl ) == 0 |
|
{ |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
remove_flist( fl ) |
|
} |
|
|
|
// final sampler controls fix |
|
if granulate |
|
{ |
|
|
|
sv_set_module_ctl_value( sv, fcount, 0, gran_vol, 2 ) |
|
sv_set_module_ctl_value( sv, fcount, 4, gran_poly, 2 ) |
|
// sv_set_module_ctl_value( sv, fcount, 6, gran_len, 2 ) |
|
|
|
} else { |
|
|
|
sv_set_module_ctl_value( sv, fcount, 0, 512, 2 ) |
|
sv_set_module_ctl_value( sv, fcount, 4, 1, 2 ) |
|
|
|
} |
|
|
|
sv_save( sv, "output.sunvox" ) |
|
|
|
sv_remove( sv ) |
|
|
|
// function for getting the required length of the pattern from the wav file length |
|
fn get_track_pattern_length( $name, $bpm, $tpl, $mul ) |
|
{ |
|
$file = load( $name ) |
|
$sr = $file.sample_rate |
|
$sm = get_size( $file ) |
|
$ch = $file.channels |
|
|
|
$len = ( $sm / $sr ) / $ch |
|
|
|
ret( round( $len / ( ( ( 2.5 / $bpm ) ) * tpl ) ) ) |
|
|
|
} |
|
|
|
// simple function for rounding numbers |
|
fn round( $num ) { |
|
|
|
$dec = $num - floor($num) |
|
|
|
if $dec < 0.5 |
|
{ |
|
|
|
ret( $num - $dec ) |
|
|
|
} else { |
|
|
|
ret( ( $num - $dec ) + 1 ) |
|
|
|
} |
|
|
|
} |
|
|
|
|