Beispiel #1
0
function createGenome($scale, $octaves = 1, $length = 16, $phraseLength = 8)
{
	//global $scale;
	
	$genome = array();
	$degrees = array(1,4,5);
	for($i = 0; $i < $length; $i++)
	{
		//$genome[] = getNoteFromDegrees($scale, $octaves, $degrees);
	
		//$genome[$i] = rand(1,16);
		if (!($i % $phraseLength)) //if beginning of phrase
		{	//get a nice note from the triad
			$genome[] = getNoteFromTriad($scale, $octaves);
			//getNoteOnScale($scale);
		}
		
		elseif (!(($i+($phraseLength+1)) % $phraseLength))
		{	//if this is the last note of the phrase
			$genome[] = getNoteOnNativeChord($scale, $octaves, 1);
		}
		
		else
		{	//get any note on scale
			$genome[] = getNoteOnScale($scale, $octaves);
		}
	
	}
	var_dump($genome);
	return $genome;
}
Beispiel #2
0
function createGenome()
{
	global $scale;
	$genome = array();
	for($i = 0; $i < 16; $i++) {
		//$genome[$i] = rand(1,16);
		$genome[] = getNoteOnScale($scale['major']);
	}
	return $genome;
}
Beispiel #3
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 #4
0
#!/usr/bin/env php
<?php
echo "Nandu project".PHP_EOL;

$scale['major']['notes'] = array(1,3,5,6,8,10,12);
$scale['major']['length'] = 12;

$octaves = 2;

$note = getNoteOnScale($scale['major'], $octaves);
echo $note.PHP_EOL;

function debug($message)
{
	echo 'DEBUG: '.$message.' @ '.whereCalled().PHP_EOL;
}

function whereCalled( $level = 1 )
{
	$trace = debug_backtrace();
//	$file   = $trace[$level]['file'];
	$line   = $trace[$level]['line'];
//	$object = $trace[$level]['object'];
//	if (is_object($object)) { $object = get_class($object); }
	return "line $line";
}

function getNoteOnScale($scale, $octaves)
{
	$pitchesAllowed = array();
	foreach($scale['notes'] as $pitch)