Last active
October 14, 2015 21:31
-
-
Save jeffgreenca/5639da2e0ed1e8b142c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Powershell script to generate SFZ file, MIDI file, and regions for REAPER DAW | |
$alphabet = "c,c#,d,d#,e,f,f#,g,g#,a,a#,b," -split "," | |
$midiNotes = @() | |
$n = 0 | |
$oct = 0 | |
for($i = 0; $i -lt 127; $i++) { | |
$midiNotes += ($alphabet[$n] + $oct) | |
$n = $n + 1 | |
if($n -eq 12) { $n = 0; $oct = $oct + 1 } | |
} | |
# Load $midiNotes translation table | |
# Where $x is any MIDI note number, $midiNotes[$x] is the sfz note label | |
$region = @" | |
<region> | |
sample=nNN.vVV.flac | |
pitch_keycenter=NL | |
lokey=NL | |
hikey=NL | |
lovel=LV | |
hivel=VV | |
"@ | |
for($noteId = 9; $noteId -lt 97; $noteId++) { | |
@(31, 63, 95, 127) | foreach { | |
$myRegion = $region | |
$myRegion = $myRegion.replace("NN", $noteId) | |
$myRegion = $myRegion.replace("NL", $midiNotes[$noteId]) | |
$myRegion = $myRegion.replace("LV", ($_ - 31).ToString()) | |
$myRegion = $myRegion.replace("VV", ($_).ToString()) | |
write-output $myRegion | |
} | |
} | |
#MIDI CSV Generation | |
$interval = 960 | |
$tick = $interval #Offset start of performance by one interval | |
for($noteId = 9; $noteId -lt 97; $noteId++) { | |
@(31, 63, 95, 127) | foreach { | |
write-output "2, $tick, Note_on_c, 0, $noteId, $_" | |
$tick = $tick + $interval | |
write-output "2, $tick, Note_off_c, 0, $noteId, 0" | |
$tick = $tick + $interval | |
} | |
} | |
function incBeat($beat) { | |
$beat++ | |
if ($beat -gt 4) { $beat = 1; } | |
return $beat; | |
} | |
$beat = 2 | |
$measure = 1 | |
$regionId = 0 | |
for($noteId = 9; $noteId -lt 97; $noteId++) { | |
@(31, 63, 95, 127) | foreach { | |
$regionId++ | |
$r = $regionId | |
$name = "n$noteId.v$_" | |
$start = "$measure.$beat.00" | |
$beat = incBeat($beat) | |
if($beat -eq 1) { $measure++ } | |
$end = "$measure.$beat.00" | |
$beat = incBeat($beat) | |
if($beat -eq 1) { $measure++ } | |
$duration = "0.1.00" | |
write-output "R$r,$name,$start,$end,$duration" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment