Пример #1
0
function replaceNextMatchingNote($text, $instr_val, $dur, $donor)
{
    $stave_start = findStaveN($text, $instr_val, 0);
    $pattern = "/:" . $dur . "\\(?[A-G][#@n]?\\*/";
    $matches = [];
    preg_match($pattern, $text, $matches, PREG_OFFSET_CAPTURE, $stave_start);
    $match_index = $matches[0][1];
    $star_index = strpos($text, '*', $match_index);
    $first_portion = substr($text, 0, $star_index);
    $second_portion = substr($text, $star_index + 1);
    $concatenated = $first_portion . $donor . $second_portion;
    return $concatenated;
}
Пример #2
0
function findAvailableNotes($s, $n)
{
    $stave = findStaveN($s, $n, 0);
    // Count 32nd notes
    $matches = array();
    preg_match_all("/:32\\(?[A-G][#@n]?\\*/", $stave, $matches);
    $thirtyseconds = isset($matches[0]) ? count($matches[0]) : 0;
    // Count 16th notes
    $matches = array();
    preg_match_all("/:16\\(?[A-G][#@n]?\\*/", $stave, $matches);
    $sixteenths = isset($matches[0]) ? count($matches[0]) : 0;
    // Count 8th notes
    $matches = array();
    preg_match_all("/:8\\(?[A-G][#@n]?\\*/", $stave, $matches);
    $eighths = isset($matches[0]) ? count($matches[0]) : 0;
    // Count dotted 8th notes
    $matches = array();
    preg_match_all("/:8d\\(?[A-G][#@n]?\\*/", $stave, $matches);
    $dotted_eighths = isset($matches[0]) ? count($matches[0]) : 0;
    // Count quarter notes
    $matches = array();
    preg_match_all("/:4\\(?[A-G][#@n]?\\*/", $stave, $matches);
    $quarters = isset($matches[0]) ? count($matches[0]) : 0;
    // Count dotted quarter notes
    $matches = array();
    preg_match_all("/:4d\\(?[A-G][#@n]?\\*/", $stave, $matches);
    $dotted_quarters = isset($matches[0]) ? count($matches[0]) : 0;
    // Count half notes
    $matches = array();
    preg_match_all("/:h\\(?[A-G][#@n]?\\*/", $stave, $matches);
    $halves = isset($matches[0]) ? count($matches[0]) : 0;
    // Count dotted half notes
    $matches = array();
    preg_match_all("/:hd\\(?[A-G][#@n]?\\*/", $stave, $matches);
    $dotted_halves = isset($matches[0]) ? count($matches[0]) : 0;
    // Count whole notes
    $matches = array();
    preg_match_all("/:w\\(?[A-G][#@n]?\\*/", $stave, $matches);
    $wholes = isset($matches[0]) ? count($matches[0]) : 0;
    $occurances = array("eighths" => $eighths, "sixteenths" => $sixteenths, "quarters" => $quarters, "halves" => $halves, "wholes" => $wholes, "dotted_quarters" => $dotted_quarters, "dotted_halves" => $dotted_halves, "dotted_eighths" => $dotted_eighths, "thirtyseconds" => $thirtyseconds);
    return $occurances;
}