Bootstart To Convert Ni Maschine Instruments Samples To Xrni


(dupoxy) #1

The NI Maschine Library/Samples/Instruments look like this:

  
Sax Section 1 Bb1.wav Sax Section 1 Db3.wav Sax Section 1 E4.wav  
Sax Section 1 Bb2.wav Sax Section 1 Db4.wav Sax Section 1 E5.wav  
Sax Section 1 Bb3.wav Sax Section 1 Db5.wav Sax Section 1 G1.wav  
Sax Section 1 Bb4.wav Sax Section 1 E1.wav Sax Section 1 G2.wav  
Sax Section 1 C1.wav Sax Section 1 E2.wav Sax Section 1 G4.wav  
Sax Section 1 Db2.wav Sax Section 1 E3.wav  

so I managed to do this : Sample2xrni

$ ./Sample2xrni -path "/media/OS/Users/olivier/Maschine Library/Samples/Instruments/Brass/Sax Section 1 Samples" -name "Sax Section.xrni" -renoise "yes"   
os.Create: Instrument.xml @ /home/olivier/Bureau/Sample2xrni  
os.Mkdir:/SampleData @ /home/olivier/Bureau/Sample2xrni  
CopyFile: Sax Section 1 Bb1.wav to /SampleData Sample0(Sax Section 1 Bb1).wav  
...  
CopyFile: Sax Section 1 G4.wav to /SampleData Sample16(Sax Section 1 G4).wav  
[/usr/bin/zip -r Sax Section.xrni Instrument.xml SampleData]  
 adding: Instrument.xml (deflated 92%)  
 adding: SampleData/ (stored 0%)  
 adding: SampleData/Sample15(Sax Section 1 G2).wav (deflated 13%)  
 ...  
 adding: SampleData/Sample2(Sax Section 1 Bb3).wav (deflated 14%)  
created: Sax Section.xrni  
Remove: Instrument.xml  
Remove: /SampleData  
[/usr/local/bin/renoise-2.7.0 renoise Sax Section.xrni]  
$ ./Sample2xrni  
 Usage of Sample2xrni:  
-OctaveSetup="0": Octave Setup 0 12 -12  
-name="out.xrni": name of xrni  
-path*="": path to samples path should have .wav files  
 that ends with " c3" and " Db3/C#3" before ".wav"  
 note "c4" = midi "48" modify using -OctaveSetup  
-renoise="no": to run renoise use -renoise "yes"  
-rpath="/usr/local/bin/renoise-2.7.0": renoise path  
-zpath="/usr/bin/zip": zip path  
  
 *required  

ugly code : Sample2xrni.go

[details=“Click to view contents”] ```

package main

import (
“fmt”
“path/filepath”
“io”
“io/ioutil”
“os”
“strings”
“strconv”
“flag”
“exec”
)

func runCmd(cmdargs …string) {
fmt.Println(cmdargs)
c, e := exec.Run(cmdargs[0], cmdargs, os.Environ(), “”,
exec.PassThrough, exec.PassThrough, exec.PassThrough)
if e != nil {
panic(e)
}
c.Wait(0)
c.Close()

}
func Note2midi(note string) int {
midi := map[string]int{
“C0”: 0, “C#0”: 1, “D0”: 2, “D#0”: 3, “E0”: 4, “F0”: 5,
“F#0”: 6, “G0”: 7, “G#0”: 8, “A0”: 9, “A#0”: 10, “B0”: 11,
“C1”: 12, “C#1”: 13, “D1”: 14, “D#1”: 15, “E1”: 16, “F1”: 17,
“F#1”: 18, “G1”: 19, “G#1”: 20, “A1”: 21, “A#1”: 22, “B1”: 23,
“C2”: 24, “C#2”: 25, “D2”: 26, “D#2”: 27, “E2”: 28, “F2”: 29,
“F#2”: 30, “G2”: 31, “G#2”: 32, “A2”: 33, “A#2”: 34, “B2”: 35,
“C3”: 36, “C#3”: 37, “D3”: 38, “D#3”: 39, “E3”: 40, “F3”: 41,
“F#3”: 42, “G3”: 43, “G#3”: 44, “A3”: 45, “A#3”: 46, “B3”: 47,
“C4”: 48, “C#4”: 49, “D4”: 50, “D#4”: 51, “E4”: 52, “F4”: 53,
“F#4”: 54, “G4”: 55, “G#4”: 56, “A4”: 57, “A#4”: 58, “B4”: 59,
“C5”: 60, “C#5”: 61, “D5”: 62, “D#5”: 63, “E5”: 64, “F5”: 65,
“F#5”: 66, “G5”: 67, “G#5”: 68, “A5”: 69, “A#5”: 70, “B5”: 71,
“C6”: 72, “C#6”: 73, “D6”: 74, “D#6”: 75, “E6”: 76, “F6”: 77,
“F#6”: 78, “G6”: 79, “G#6”: 80, “A6”: 81, “A#6”: 82, “B6”: 83,
“C7”: 84, “C#7”: 85, “D7”: 86, “D#7”: 87, “E7”: 88, “F7”: 89,
“F#7”: 90, “G7”: 91, “G#7”: 92, “A7”: 93, “A#7”: 94, “B7”: 95,
“C8”: 96, “C#8”: 97, “D8”: 98, “D#8”: 99, “E8”: 100, “F8”: 101,
“F#8”: 102, “G8”: 103, “G#8”: 104, “A8”: 105, “A#8”: 106, “B8”: 107,
“C9”: 108, “C#9”: 109, “D9”: 110, “D#9”: 111, “E9”: 112, “F9”: 113,
“F#9”: 114, “G9”: 115, “G#9”: 116, “A9”: 117, “A#9”: 118, “B9”: 119,
“C10”: 120, “C#10”: 121, “D10”: 122, “D#10”: 123, “E10”: 124, “F10”: 125,
“F#10”: 126, “G10”: 127,
}
return midi[note]
}
// return true or false for .wav
func isWavFile(f *os.FileInfo) bool {
return f.IsRegular() &&
!strings.HasPrefix(f.Name, “.”) && // ignore .files
filepath.Ext(f.Name) == “.wav”
}
//load Name from current path
func loadName(name string, f io.Writer) {
fmt.Fprintf(f, “%v\n”, name)

}

//CopyFile
func CopyFile(dst, src string, from string, to string) (int64, os.Error) {
os.Chdir(from)
sf, err := os.Open(src)
if err != nil {
return 0, err
}
defer sf.Close()
os.Chdir(to)
df, err := os.Create(dst)
if err != nil {
return 0, err
}
defer df.Close()
return io.Copy(df, sf)
}
//load Dir from current path
func loadDir(pathtosamples string, scriptpath string, f io.Writer, iOctave int) {

list, err := ioutil.ReadDir(pathtosamples)
if err != nil {
fmt.Printf(“Error: %s\n”, err)
return
}
// Create the directory
os.Mkdir(scriptpath+"/SampleData", 0755)
fmt.Println(“os.Mkdir:/SampleData @”, scriptpath)
// Print out the Sample list.
fmt.Fprintf(f, “\n”)

SampleIndex := 0

for _, e := range list {

// fmt.Printf("%v\n", isWavFile(e));



if isWavFile(e) == true {

//fmt.Printf(“wav%d: %v\n”, SampleIndex, e.Name)

fmt.Fprintf(f, “\n”)

WavFile := strings.Split(e.Name, “.wav”, -1)

for _, Name := range WavFile {

if Name != “” {

fmt.Fprintf(f, “%v\n”, Name)

fmt.Fprintf(f, “SampleData/Sample%d (%v).wav\n”, SampleIndex, Name)



//copy wav to /SampleData and rename

fn := e.Name

sn := “Sample” + strconv.Itoa(SampleIndex) + “(” + Name + “)” + “.wav”

from := pathtosamples

to := scriptpath + “/SampleData”

n, err := CopyFile(sn, fn, from, to)

if err != nil {

fmt.Println(n, err)

}

fmt.Println(“CopyFile:”, fn, “to /SampleData”, sn)

fmt.Fprintf(f, “1640-01-01\n”)

fmt.Fprintf(f, “00:00:00\n”)

fmt.Fprintf(f, “1\n”)

fmt.Fprintf(f, “0.5\n”)

Nsplit := strings.SplitAfter(Name, " ", -2)

NameIndex := 0

NameIndexT := strings.Count(Name, " ")

// fmt.Printf(“NameIndexT: %d\n”, NameIndexT)

for _, splName := range Nsplit {

if splName != “” {

if NameIndex == NameIndexT {

// fmt.Printf(“splName%d: %v\n”, NameIndex, splName)

note := strings.ToUpper(splName)

for i := 0; i < 10; i++ {



midioctave := map[int]string{

0: “0”, 1: “1”, 2: “2”, 3: “3”, 4: “4”, 5: “5”,

6: “6”, 7: “7”, 8: “8”, 9: “9”, 10: “10”,

}

if note == “DB”+midioctave[i] {

note = “C#” + midioctave[i]

}

if note == “EB”+midioctave[i] {

note = “D#” + midioctave[i]

}

if note == “GB”+midioctave[i] {

note = “F#” + midioctave[i]

}

if note == “AB”+midioctave[i] {

note = “G#” + midioctave[i]

}

if note == “BB”+midioctave[i] {

note = “A#” + midioctave[i]

}



}

midinote := Note2midi(note) + iOctave // C4 = 60

// fmt.Printf(“Note MIDI Numbers %s: %d\n”, note, midinote)

fmt.Fprintf(f, “%d\n”, midinote)

fmt.Fprintf(f, “0\n”)

fmt.Fprintf(f, “0\n”)

fmt.Fprintf(f, “false\n”)

fmt.Fprintf(f, “false\n”)

fmt.Fprintf(f, “false\n”)

fmt.Fprintf(f, “16\n”)

fmt.Fprintf(f, “NoteOff\n”)

fmt.Fprintf(f, “Cubic\n”)

fmt.Fprintf(f, “Off\n”)

fmt.Fprintf(f, “false\n”)

fmt.Fprintf(f, “\n”)

fmt.Fprintf(f, “\n”)

fmt.Fprintf(f, “true\n”)

fmt.Fprintf(f, “false\n”)

}

}

NameIndex = NameIndex + 1

}

}

}

SampleIndex = SampleIndex + 1

fmt.Fprintf(f, “\n”)

} else {

fmt.Println(“no .wav file Instrument Empty”)

return

}

}

fmt.Fprintf(f, “\n”)

}

//load SplitMap from current path
func loadSplitMap(pathtosamples string, f io.Writer, iOctave int) {
list, err := ioutil.ReadDir(pathtosamples)
if err != nil {
fmt.Printf(“Error: %s\n”, err)

}
// Print out the Sample list. SplitMap
fmt.Fprintf(f, “\n”)

fmt.Fprintf(f, “\n”)

SampleIndex := 0

for _, e := range list {

// fmt.Printf("%v\n", isWavFile(e));



if isWavFile(e) == true {

//fmt.Printf(“wav%d: %v\n”, SampleIndex, e.Name)

fmt.Fprintf(f, “\n”)

WavFile := strings.Split(e.Name, “.wav”, -1)

for _, Name := range WavFile {

if Name != “” {

fmt.Fprintf(f, “%d\n”, SampleIndex)

fmt.Fprintf(f, “true\n”)

fmt.Fprintf(f, “true\n”)

Nsplit := strings.SplitAfter(Name, " ", -2)

NameIndex := 0

NameIndexT := strings.Count(Name, " ")

// fmt.Printf(“NameIndexT: %d\n”, NameIndexT)

for _, splName := range Nsplit {

if splName != “” {

if NameIndex == NameIndexT {

// fmt.Printf(“splName%d: %v\n”, NameIndex, splName)

note := strings.ToUpper(splName)

// fmt.Printf(note)

for i := 0; i < 10; i++ {



midioctave := map[int]string{

0: “0”, 1: “1”, 2: “2”, 3: “3”, 4: “4”, 5: “5”,

6: “6”, 7: “7”, 8: “8”, 9: “9”, 10: “10”,

}

if note == “DB”+midioctave[i] {

note = “C#” + midioctave[i]



}

if note == “EB”+midioctave[i] {

note = “D#” + midioctave[i]



}

if note == “GB”+midioctave[i] {

note = “F#” + midioctave[i]



}

if note == “AB”+midioctave[i] {

note = “G#” + midioctave[i]

}

if note == “BB”+midioctave[i] {

note = “A#” + midioctave[i]

}



}

midinote := Note2midi(note) + iOctave // C4 = 60

// fmt.Printf(“Note MIDI Numbers %s: %d\n”, note, midinote)

fmt.Fprintf(f, “%d\n”, midinote)

fmt.Fprintf(f, “%d\n”, midinote)

fmt.Fprintf(f, “%d\n”, midinote)

fmt.Fprintf(f, “0\n”)

fmt.Fprintf(f, “127\n”)

}

}

NameIndex = NameIndex + 1

}

}

}

SampleIndex = SampleIndex + 1

fmt.Fprintf(f, “\n”)

}

}

fmt.Fprintf(f, “\n”)

fmt.Fprintf(f, “\n”)
}

func main() {
var startXml = <?xml version="1.0" encoding="UTF-8"?> <renoiseinstrument doc_version="12"><br> <activegeneratortab>Samples</activegeneratortab><br>

var startXml2 = <br> <copyintonewsamplenamecounter>0</copyintonewsamplenamecounter><br> <copyintonewinstrumentnamecounter>0</copyintonewinstrumentnamecounter><br>

var endXml = <sampleenvelopes><br> <volume><br> <isactive>false</isactive><br> <interpolationmode>Linear</interpolationmode><br> <sustainisactive>true</sustainisactive><br> <sustainpos>0</sustainpos><br> <loopstart>0</loopstart><br> <loopend>71</loopend><br> <loopmode>Off</loopmode><br> <decay>128</decay><br> <nodes><br> <playmode>Linear</playmode><br> <length>72</length><br> <valuequantum>0.0</valuequantum><br> <polarity>Unipolar</polarity><br> <points><br> <point>0,0.9900000095367431640625</point><br> <point>3,0.047297298908233642578125</point><br> <point>6,0.391891896724700927734375</point><br> <point>9,0.12162162363529205322265625</point><br> <point>71,0.0</point><br> </points><br> </nodes><br> <lfo1><br> <mode>Off</mode><br> <frequency>8</frequency><br> <amplitude>40</amplitude><br> <dephase>45</dephase><br> </lfo1><br> <lfo2><br> <mode>Off</mode><br> <frequency>3</frequency><br> <amplitude>27</amplitude><br> <dephase>0</dephase><br> </lfo2><br> </volume><br> <pan><br> <isactive>false</isactive><br> <interpolationmode>Curve</interpolationmode><br> <sustainisactive>false</sustainisactive><br> <sustainpos>0</sustainpos><br> <loopstart>0</loopstart><br> <loopend>71</loopend><br> <loopmode>Off</loopmode><br> <decay>128</decay><br> <nodes><br> <playmode>Curve</playmode><br> <length>72</length><br> <valuequantum>0.0</valuequantum><br> <polarity>Bipolar</polarity><br> <points><br> <point>0,0.5</point><br> <point>10,0.60000002384185791015625</point><br> <point>20,0.4000000059604644775390625</point><br> <point>30,0.699999988079071044921875</point><br> <point>40,0.300000011920928955078125</point><br> <point>60,0.4000000059604644775390625</point><br> <point>71,0.5</point><br> </points><br> </nodes><br> <lfo1><br> <mode>Off</mode><br> <frequency>8</frequency><br> <amplitude>40</amplitude><br> <dephase>45</dephase><br> </lfo1><br> <lfo2><br> <mode>Off</mode><br> <frequency>3</frequency><br> <amplitude>27</amplitude><br> <dephase>0</dephase><br> </lfo2><br> </pan><br> <pitch><br> <isactive>false</isactive><br> <interpolationmode>Curve</interpolationmode><br> <sustainisactive>false</sustainisactive><br> <sustainpos>0</sustainpos><br> <loopstart>0</loopstart><br> <loopend>71</loopend><br> <loopmode>Off</loopmode><br> <decay>128</decay><br> <nodes><br> <playmode>Curve</playmode><br> <length>72</length><br> <valuequantum>0.0</valuequantum><br> <polarity>Bipolar</polarity><br> <points><br> <point>0,0.699999988079071044921875</point><br> <point>50,0.20000000298023223876953125</point><br> <point>71,0.0500000007450580596923828125</point><br> </points><br> </nodes><br> <lfo1><br> <mode>Off</mode><br> <frequency>25</frequency><br> <amplitude>10</amplitude><br> <dephase>0</dephase><br> </lfo1><br> <lfo2><br> <mode>Off</mode><br> <frequency>3</frequency><br> <amplitude>27</amplitude><br> <dephase>0</dephase><br> </lfo2><br> </pitch><br> <filtertype>3</filtertype><br> <cutoff><br> <isactive>false</isactive><br> <interpolationmode>Curve</interpolationmode><br> <sustainisactive>false</sustainisactive><br> <sustainpos>0</sustainpos><br> <loopstart>0</loopstart><br> <loopend>71</loopend><br> <loopmode>Off</loopmode><br> <decay>128</decay><br> <nodes><br> <playmode>Curve</playmode><br> <length>72</length><br> <valuequantum>0.0</valuequantum><br> <polarity>Unipolar</polarity><br> <points><br> <point>0,0.5</point><br> <point>40,0.800000011920928955078125</point><br> <point>60,0.20000000298023223876953125</point><br> <point>71,0.5</point><br> </points><br> </nodes><br> <lfo><br> <mode>Off</mode><br> <frequency>12</frequency><br> <amplitude>70</amplitude><br> <dephase>0</dephase><br> </lfo><br> <autoamp><br> <isactive>false</isactive><br> <attack>100</attack><br> <release>70</release><br> <amount>60</amount><br> </autoamp><br> </cutoff><br> <resonance><br> <isactive>false</isactive><br> <interpolationmode>Curve</interpolationmode><br> <sustainisactive>false</sustainisactive><br> <sustainpos>0</sustainpos><br> <loopstart>0</loopstart><br> <loopend>71</loopend><br> <loopmode>Off</loopmode><br> <decay>128</decay><br> <nodes><br> <playmode>Curve</playmode><br> <length>72</length><br> <valuequantum>0.0</valuequantum><br> <polarity>Unipolar</polarity><br> <points><br> <point>0,0.5</point><br> <point>40,0.20000000298023223876953125</point><br> <point>60,0.60000002384185791015625</point><br> <point>71,0.5</point><br> </points><br> </nodes><br> <lfo><br> <mode>Off</mode><br> <frequency>12</frequency><br> <amplitude>70</amplitude><br> <dephase>0</dephase><br> </lfo><br> <autoamp><br> <isactive>false</isactive><br> <attack>100</attack><br> <release>70</release><br> <amount>60</amount><br> </autoamp><br> </resonance><br> </sampleenvelopes><br> <pluginproperties><br> <channel>0</channel><br> <transpose>0</transpose><br> <volume>1.0</volume><br> <outputroutings><br> <outputrouting><br> <enabled>true</enabled><br> <name>Bus #01</name><br> <mixmode>L+R</mixmode><br> <autoassign>true</autoassign><br> <assignedtrack>-1</assignedtrack><br> </outputrouting><br> </outputroutings><br> <autosuspend>true</autosuspend><br> <aliasinstrumentindex>-1</aliasinstrumentindex><br> <aliasfxindices>-1,-1</aliasfxindices><br> </pluginproperties><br> <midiinputproperties><br> <isactive>false</isactive><br> <channel>-1</channel><br> <assignedtrack>-1</assignedtrack><br> </midiinputproperties><br> <midioutputproperties><br> <isactive>false</isactive><br> <channel>0</channel><br> <instrumenttype>ext. MIDI</instrumenttype><br> <delay>0</delay><br> <program>-1</program><br> <bank>-1</bank><br> <transpose>0</transpose><br> <length>8000</length><br> </midioutputproperties><br> </renoiseinstrument>
// set and parse Flags
var OctaveSetup = flag.String(“OctaveSetup”, “0”, “Octave Setup 0 12 -12”)
var path = flag.String(“path”, “”, “path to samples”)
var name = flag.String(“name”, “out.xrni”, “name of xrni”)
var renoise = flag.String(“renoise”, “no”, “run renoise”)
var rpath = flag.String(“rpath”, “/usr/local/bin/renoise-2.7.0”, “renoise path”)
var zpath = flag.String(“zpath”, “/usr/bin/zip”, “zip path”)
flag.Parse()
if *path != “” {
pathtosamples := *path
_, err := ioutil.ReadDir(pathtosamples)
if err != nil {
fmt.Printf(“Error: %s\n”, err)
return
}
scriptpath, err := os.Getwd()
if err != nil {
fmt.Printf(“Error: %s\n”, err)
}
// write f to Instrument.xml
src := “Instrument.xml”
f, err := os.Create(src)
if err != nil {
fmt.Printf(“Error: %s\n”, err)
}
fmt.Println(“os.Create:”, src, “@”, scriptpath)
fmt.Fprintf(f, startXml)
iname := strings.Split(*name, “.xrni”, -1)
loadName(iname[0], f)
fmt.Fprintf(f, startXml2)
iOctave, err := strconv.Atoi(*OctaveSetup)
if err != nil {
fmt.Printf(“Error: %s\n”, err)
}
loadDir(pathtosamples, scriptpath, f, iOctave)
loadSplitMap(pathtosamples, f, iOctave)
fmt.Fprintf(f, endXml)
os.Chdir(scriptpath)
if err != nil {
fmt.Printf(“Error: %s\n”, err)
}
runCmd(*zpath, “-r”, *name, src, “SampleData”)
fmt.Println(“created:”, *name)
os.Remove(src)
fmt.Println(“Remove:”, src)
os.RemoveAll(“SampleData”)
fmt.Println(“Remove: /SampleData”)
if *renoise == “yes” {
runCmd(*rpath, “renoise”, name)
} else {
}
} else {
help := ` Usage of Sample2xrni:
-OctaveSetup=“0”: Octave Setup 0 12 -12
-name=“out.xrni”: name of xrni
-path
="": path to samples path should have .wav files
that ends with " c3" and " Db3/C#3" before “.wav”
note “c4” = midi “48” modify using -OctaveSetup
-renoise=“no”: to run renoise use -renoise “yes”
-rpath="/usr/local/bin/renoise-2.7.0": renoise path
-zpath="/usr/bin/zip": zip path

*required

ex: ./Sample2xrni -path “/path/to samples/”`
fmt.Println(help)
}
}

[/details]