Beispiel #1
0
function getNoteFromTriad($scale, $octaves=1)
{
	$selectedDegree = $scale['triad'][array_rand($scale['triad'])];
	return getNoteOnNativeChord($scale, $octaves, $selectedDegree);
}
Beispiel #2
0
function createGenome($scale, $octaves = 1, $length = 16, $phraseLength = 8)
{
	//eval(globals()); // get all the probability objects
	global $pFirstPhraseNoteOnTriad, $pNoteOnScale, $pLastPhraseNoteOnTriad, $pLastNoteOnTriad, $pLastNoteOnTonic;
	
	$genome = array();
	for($i = 0; $i < $length; $i++)
	{
		//$genome[$i] = rand(1,16);
		
		if (!($i % $phraseLength)) //if beginning of phrase
		{	//get a nice note from the triad
			if ($pFirstPhraseNoteOnTriad->get()) $genome[] = getNoteFromTriad($scale, $octaves);
			elseif ($pNoteOnScale->get()) $genome[] = getNoteOnScale($scale, $octaves);
			else $genome[] = getNoteRandom($scale, $octaves);
		}
		
		elseif (!(($i+($phraseLength+1)) % $phraseLength))
		{	//if this is the last note of the phrase
			//get a nice note from 'I'
			if ($pLastPhraseNoteOnTriad->get()) $genome[] = getNoteFromTriad($scale, $octaves);
			elseif ($pNoteOnScale->get()) $genome[] = getNoteOnScale($scale, $octaves);
			else $genome[] = getNoteRandom($scale, $octaves);
		}
		
		elseif ($i == ($length - 1))
		{	//if this is the last note of the melody
			if ($pLastNoteOnTriad->get())
			{	// need to change this to an actual tonic, not just a note from the tonic chord (or add another level)
				if ($pLastNoteOnTonic->get()) $genome[] = getNoteOnNativeChord($scale, $octaves, 1);
				else $genome[] = getNoteFromTriad($scale, $octaves);
			}
			elseif ($pNoteOnScale->get()) $genome[] = getNoteOnScale($scale, $octaves);
			else $genome[] = getNoteRandom($scale, $octaves);
		}
		
		else
		{	//get any note on scale
			if ($pNoteOnScale->get()) $genome[] = getNoteOnScale($scale, $octaves);
			else $genome[] = getNoteRandom($scale, $octaves);
			//echo getNoteOnScale($scale, $octaves).' - ';
		}
	
	}
	//var_dump($genome);
	return $genome;
}
Beispiel #3
0
<?php

require_once (__DIR__.'/functions.php');
//$genome = array(createGenome($scales['major'], 2, 16, 8), createGenome($scales['major']));

//getNoteInProximityOnScale($scales['major'], 20, 3)

//var_dump (getDegreeWithOctaveFromNote(getNoteFromTriad($scales['major'], 1),$scales['major']));

var_dump (getDegreeWithOctaveFromNote(getNoteOnNativeChord($scales['major'], 1, 0, TRUE), $scales['major']));

//var_dump (getNoteIntervalOnScale($scales['major'], 2, -3));
?>