<?php
 
/************************************************************* 
 
 * This script is developed by Arturs Sosins aka ar2rsawseen, http://webcodingeasy.com 
 
 * Fee free to distribute and modify code, but keep reference to its creator 
 
 * 
 
 * This class implements music theory for generating scales and chords
 
 * based on interval patterns between notes. User can add custom scale and chord pattern.
 
 * This class can generate scale notes based on provided scale name and type,
 
 * generate chord notes based on provided chord name and type,
 
 * transpose scales, transpose chords,
 
 * generate all chords that include provided notes,
 
 * generate all scales that include provided notes,
 
 * 
 
 * For more information, examples and online documentation visit:  
 
 * http://webcodingeasy.com/PHP-classes/Implement-music-theory-to-generate-scale-and-chord-notes 
 
**************************************************************/
 
 
//declaring class instance
 
include("./music_theory.php");
 
$mt = new music_theory();
 
 
//sharp notation will be used
 
$mt->set_sharp();
 
 
/**************** Get scale by name *************************/
 
echo "<p>Get Scales, input: (C minor):</p>";
 
 
//get result array
 
$arr = $mt->get_scale_by_name("C", "minor");
 
 
//check if there were any errors
 
$errors = $mt->get_errors();
 
if(!empty($errors))
 
{
 
    foreach($errors as $error)
 
    {
 
        echo "<p>".$error."</p>";
 
    }
 
}
 
else
 
{
 
    echo "<pre>";
 
    print_r($arr);
 
    echo "</pre>";
 
}
 
 
/**************** Get chord by name *************************/
 
 
echo "<p>Get Chord, input: (C major):</p>";
 
 
//get result array
 
$arr = $mt->get_chord_by_name("C", "major", 1);
 
 
//check if there were any errors
 
$errors = $mt->get_errors();
 
if(!empty($errors))
 
{
 
    foreach($errors as $error)
 
    {
 
        echo "<p>".$error."</p>";
 
    }
 
}
 
else
 
{
 
    echo "<pre>";
 
    print_r($arr);
 
    echo "</pre>";
 
}
 
 
/**************** Get chords by ņotes *************************/
 
 
echo "<p>Get Chords by notes, input:(C, A, F):</p>";
 
 
//get result array
 
$arr = $mt->get_chords_by_notes(array("c","a","f"));
 
 
//check if there were any errors
 
$errors = $mt->get_errors();
 
if(!empty($errors))
 
{
 
    foreach($errors as $error)
 
    {
 
        echo "<p>".$error."</p>";
 
    }
 
}
 
else
 
{
 
    echo "<pre>";
 
    print_r($arr);
 
    echo "</pre>";
 
}
 
 
/**************** Get scales by ņotes *************************/
 
 
echo "<p>Get Scales by notes, input: (C, A, F):</p>";
 
 
//get result array
 
$arr = $mt->get_scales_by_notes(array("c","a","f"));
 
 
//check if there were any errors
 
$errors = $mt->get_errors();
 
if(!empty($errors))
 
{
 
    foreach($errors as $error)
 
    {
 
        echo "<p>".$error."</p>";
 
    }
 
}
 
else
 
{
 
    echo "<pre>";
 
    print_r($arr);
 
    echo "</pre>";
 
}
 
 
/**************** Get scales by chords *************************/
 
 
echo "<p>Get Scales by chords, input (C major and A minor):</p>";
 
 
$chords = array(array("name" => "C", "type" => "major"), array("name" => "A", "type" => "minor"));
 
 
//get result array
 
$arr = $mt->get_scales_by_chords($chords);
 
 
//check if there were any errors
 
$errors = $mt->get_errors();
 
if(!empty($errors))
 
{
 
    foreach($errors as $error)
 
    {
 
        echo "<p>".$error."</p>";
 
    }
 
}
 
else
 
{
 
    echo "<pre>";
 
    print_r($arr);
 
    echo "</pre>";
 
}
 
 
/**************** Get scales by chords *************************/
 
 
echo "<p>Get Chords by scale, input: (C minor):</p>";
 
 
//get result array
 
$arr = $mt->get_chords_by_scale("C", "minor");
 
 
//check if there were any errors
 
$errors = $mt->get_errors();
 
if(!empty($errors))
 
{
 
    foreach($errors as $error)
 
    {
 
        echo "<p>".$error."</p>";
 
    }
 
}
 
else
 
{
 
    echo "<pre>";
 
    print_r($arr);
 
    echo "</pre>";
 
}
 
?>
 
 
 |