Skip to content

Instantly share code, notes, and snippets.

@TheBlackParrot
Last active September 2, 2015 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheBlackParrot/433ae0cda00c280f8118 to your computer and use it in GitHub Desktop.
Save TheBlackParrot/433ae0cda00c280f8118 to your computer and use it in GitHub Desktop.
<?php
$notes = explode(" ", "NC NCS ND NDS NE NF NFS NG NGS NA NAS NB");
$inst = "SteelDrum";
$start_octave = 2;
$preview = 1;
$location = "/tmp";
$dir = new DirectoryIterator($location);
foreach ($dir as $fileinfo) {
if($fileinfo->isDot()) {
continue;
}
if($fileinfo->getExtension() == "wav") {
$fullname = $fileinfo->getFilename();
$filename = substr($fullname, 0, stripos($fullname, "."));
$channel = substr($filename, stripos($filename, "-")+1);
//str_replace(search, replace, subject)
$note = str_replace("N", ceil($channel / 12)+($start_octave-1), $notes[($channel-1) % 12]);
echo "$filename --> {$inst}_{$note}\n";
if(!$preview) {
exec("mv $location/$fullname $location/{$inst}_{$note}.wav");
}
echo("mv $location/$fullname $location/{$inst}_{$note}.wav\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment