Xrni.pl - Generate Xrni Files From The Command-Line

Hi, just started a small GitHub project called renoise-perl-utils - Renoise Perl command-line utilities

For now, the GitHub repository contains the following command-line utility: xrni.pl - generate Renoise XRNI files

An XRNI file is basically a zip file, with the XML file Instrument.xml and a SampleData/ dir containing the wav/flac samples.

The Perl function example_sincos() works as follows:

  • 1st generate the wav files in the SampleData/ directory, - 2nd generate the Instrument.xml, and finally - 3rd compress the generated files into the final zip archive (xrni file).

The Perl function example_sincos() looks like follows:

sub example_sincos {  
 if (!$out) {u("missing --out [dir], eg.: build.")}  
 if (!-d $out){u("--out dir \"".$out."\" does not exist.")}  
 my $file = $out."/"."sincos.xrni";  
  
 # write wav sample file(s)  
 my ($sample_rate, $bits_sample, $channels) = (96000, 16, 2);  
 my $wav = gen_wav($out.'/SampleData/Sample00 (sine).wav',  
 $sample_rate, $bits_sample, $channels);  
  
 my $hz = midi2hz(12); my $len = 1.0 / $hz; $len *= $sample_rate; # C0 == 12  
 print STDERR " hz = ".$hz." Hz\n len = ".$len." samples\n";  
 my $max = (2 ** $bits_sample)/2-1; ## max amplitude in the wav file  
  
 for my $pos (0 .. $len) { my $t = $pos / $sample_rate; $t *= $hz;  
 my $left = sin(2 * PI * $t) * 1.0;  
 my $right = cos(2 * PI * $t) * 1.0;  
 # $wav->write($left * $max); # mono  
 $wav->write(($left * $max, $right * $max)); # stereo  
 } $wav->finish(); # write wav file headers and close wav file  
  
 # write Instrument.xml  
 my ($dom, $xrni) = gen_dom_xrni("Sine L Cosine R");  
 my $Samples = XML::LibXML::Element->new("Samples");  
  
 # Name, FileName, BaseNote, LoopMode, LoopStart, LoopEnd  
 add_sample($Samples, "Sample", "sine", 0, "Forward", 0, $len + 1);  
 $xrni->appendChild($Samples);  
  
 # add NoteOnMappings  
 my $SampleSplitMap = XML::LibXML::Element->new("SampleSplitMap");  
 my $NoteOnMappings = XML::LibXML::Element->new("NoteOnMappings");  
 $SampleSplitMap->appendChild($NoteOnMappings);  
 $xrni->appendChild($SampleSplitMap);  
  
 # SampleIndex, BaseNote, NoteStart, NoteEnd, VelocityStart, VelocityEnd  
 add_note_on_mapping($NoteOnMappings, 0, 0, 0, 127, 0, 127); # C0 - A8  
  
 # add_sample_envelopes($xrni); add_plugin_properties($xrni);  
 # add_midi_input_properties($xrni); add_midi_output_properties($xrni);   
  
 writeFile($out."/"."Instrument.xml", $dom->toString(), ":utf8");  
  
 # write XRNI (zip file with sample wav files)  
 gen_xrni($out, $file, ("SampleData/Sample00 (sine).wav"));  
}  

Feel free to fork the repository and adapt the XRNI gen code to your needs.