|
From: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - 2007-09-23 19:49:56
|
Update of /cvsroot/xrns-php/xrns-php/scripts In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv19078 Modified Files: xrns_randomizer.cfg xrns_randomizer.php Log Message: New randomize modes based on scales, option to keep note octave. Index: xrns_randomizer.php =================================================================== RCS file: /cvsroot/xrns-php/xrns-php/scripts/xrns_randomizer.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** xrns_randomizer.php 2 Sep 2007 15:50:36 -0000 1.5 --- xrns_randomizer.php 23 Sep 2007 19:49:53 -0000 1.6 *************** *** 4,11 **** Requires: PHP5 and Info-Zip (http://www.info-zip.org/) ! Usage: `php xrns_randomizer.php /path/to/file1.xrns file2.xrns [chaos|shuffle]` Will output randomized file to current working directory ! Public Domain, last modified August 25th, 2007 Coded by XXXXXXXXXXXXX of http://www.trotch.com/ --- 4,11 ---- Requires: PHP5 and Info-Zip (http://www.info-zip.org/) ! Usage: `php xrns_randomizer.php /path/to/file1.xrns file2.xrns [mode] [keep_octave]` Will output randomized file to current working directory ! Public Domain, last modified September 23rd, 2007 Coded by XXXXXXXXXXXXX of http://www.trotch.com/ *************** *** 20,23 **** --- 20,36 ---- // ---------------------------------------------------------------------------- + $valid_modes = array( + 'chaos', + 'shuffle', + 'harmonic_minor', + 'locrian', + 'lydian', + 'melodic_minor', + 'pentatonic_blues', + 'pentatonic_major', + 'pentatonic_minor', + 'pentatonic_netural', + ); + $tmp_dir = '/tmp'; *************** *** 32,46 **** // ---------------------------------------------------------------------------- ! function randomize_note() { ! $letter = 'ABCDEFG'; ! $symbol = '-#'; ! $number = '0123456789'; ! $random = ''; ! $random .= substr($letter, mt_rand(0, strlen($letter)-1), 1); ! if ($random == 'B' || $random == 'E') $random .= '-'; ! else $random .= substr($symbol, mt_rand(0, strlen($symbol)-1), 1); ! $random .= substr($number, mt_rand(0, strlen($number)-1), 1); return $random; --- 45,96 ---- // ---------------------------------------------------------------------------- ! function randomize_note($mode = null, $note = null) { ! // Scales ! $notes = array(); ! if ($mode == 'harmonic_minor') { ! // Harmonic Minor ! $notes = array('C-', 'D-', 'D#', 'F-', 'G-', 'G#'); ! } ! else if ($mode == 'locrian') { ! // Locrian ! $notes = array('C-', 'C#', 'D#', 'F-', 'F#', 'G#', 'A#', 'C-'); ! } ! else if ($mode == 'lydian') { ! // Lydian ! $notes = array('C-', 'D-', 'E-', 'F#', 'G-', 'A-', 'B-'); ! } ! else if ($mode == 'melodic_minor') { ! // Melodic minor ! $notes = array('C-', 'D-', 'D#', 'F-', 'G-', 'A-', 'B-'); ! } ! else if ($mode == 'pentatonic_blues') { ! // Pentatonic Blues ! $notes = array('C-', 'D#', 'F-', 'F#', 'G-'); ! } ! else if ($mode == 'pentatonic_major') { ! // Pentatonic Major ! $notes = array('C-', 'D-', 'F-', 'G-', 'A-'); ! } ! else if ($mode == 'pentatonic_minor') { ! // Pentatonic Minor ! $notes = array('C-', 'D#', 'F-', 'G-', 'A#'); ! } ! else if ($mode == 'pentatonic_netural') { ! // Pentatonic Minor ! $notes = array('C-', 'D-', 'F-', 'G-', 'A#'); ! } ! else { ! // Chaos, all notes ! $notes = array('C-', 'C#', 'D-', 'D#', 'E-', 'F-', 'F#', 'G-', 'G#', 'A-', 'A#', 'B-'); ! } ! // Octaves ! $number = null; ! if ($note) $number = substr($note, -1, 1); // Preserve octave ! if (!ctype_digit($number)) $number = rand(0, 9); // Pick a random octave ! ! $key = array_rand($notes); ! $random = $notes[$key] . $number; return $random; *************** *** 66,70 **** if ($argc < 3) { echo "Error: $argv[0] expects at least 2 parameters.\n"; ! echo "Usage: `php $argv[0] /path/to/file1.xrns file2.xrns [chaos|shuffle]`\n"; echo "$argv[0] will output randomized file (file2.xrns) to current working directory.\n"; die(); --- 116,121 ---- if ($argc < 3) { echo "Error: $argv[0] expects at least 2 parameters.\n"; ! echo "Usage: `php $argv[0] /path/to/file1.xrns file2.xrns [mode] [keep_octave]`\n"; ! echo "Valid modes are: \n * ", implode("\n * ", $valid_modes) . "\n"; echo "$argv[0] will output randomized file (file2.xrns) to current working directory.\n"; die(); *************** *** 77,85 **** } $song1 = $argv[1]; $song2 = $argv[2]; $mode = 'chaos'; // Default ! if (isset($argv[3]) && strtolower($argv[3]) == 'shuffle') $mode = 'shuffle'; // ---------------------------------------------------------------------------- --- 128,144 ---- } + // File names $song1 = $argv[1]; $song2 = $argv[2]; + // Mode $mode = 'chaos'; // Default ! if (isset($argv[3])) { ! if (in_array(strtolower($argv[3]), $valid_modes)) $mode = strtolower($argv[3]); ! } ! ! // Keep Octave ! $keep_octave = (isset($argv[4]) && $argv[4] != 0) ? true : false; ! // ---------------------------------------------------------------------------- *************** *** 110,116 **** // ---------------------------------------------------------------------------- ! switch($mode) { ! ! case ('shuffle'): // Mode: shuffle --- 169,173 ---- // ---------------------------------------------------------------------------- ! if ($mode == 'shuffle') { // Mode: shuffle *************** *** 149,161 **** } ! break; ! ! ! default: - // Mode: chaos - // Randomize every note in the entire song ! echo "Mode: chaos \n"; foreach ($sx1->PatternPool->Patterns->Pattern as $p) { foreach ($p->Tracks->PatternTrack as $x) { --- 206,216 ---- } ! } ! else { ! echo "Mode: $mode"; ! if ($keep_octave) echo ", will preserve octave"; ! echo "\n"; foreach ($sx1->PatternPool->Patterns->Pattern as $p) { foreach ($p->Tracks->PatternTrack as $x) { *************** *** 165,169 **** foreach ($y->NoteColumns->NoteColumn as $z) { if ($z->Note && $z->Note != 'OFF') { ! $z->Note = randomize_note(); } } --- 220,227 ---- foreach ($y->NoteColumns->NoteColumn as $z) { if ($z->Note && $z->Note != 'OFF') { ! ! if ($keep_octave) $z->Note = randomize_note($mode, $z->Note); ! else $z->Note = randomize_note($mode); ! } } *************** *** 174,177 **** --- 232,236 ---- } + } Index: xrns_randomizer.cfg =================================================================== RCS file: /cvsroot/xrns-php/xrns-php/scripts/xrns_randomizer.cfg,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** xrns_randomizer.cfg 25 Aug 2007 15:20:24 -0000 1.2 --- xrns_randomizer.cfg 23 Sep 2007 19:49:53 -0000 1.3 *************** *** 1,6 **** [config] ! caption=XRNS Randomizer 1.0 author=Coded by XXXXXXXXXXXXX. url=http://www.trotch.com/xrns_scripts description=XRNS Randomizer is a script, which allows you to randomize a XRNS file using one of two different randomization modes and save the result into a new file. ! gui=label(Select the file you want to randomize:); file(def:xrns, zip); label(Specify the destination file:); output(def:xrns, zip); label(Select a randomization mode:); options(def:chaos, shuffle) --- 1,6 ---- [config] ! caption=XRNS Randomizer author=Coded by XXXXXXXXXXXXX. url=http://www.trotch.com/xrns_scripts description=XRNS Randomizer is a script, which allows you to randomize a XRNS file using one of two different randomization modes and save the result into a new file. ! gui=label(Select the file you want to randomize:); file(def:xrns, zip); label(Specify the destination file:); output(def:xrns, zip); label(Select a randomization mode:); options(def:chaos, shuffle, harmonic_minor, locrian, lydian, melodic_minor, pentatonic_blues, pentatonic_major, pentatonic_minor, pentatonic_netural); label(Keep octave?:); options(def:0, 1); |