Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois Schwarzentruber committed May 19, 2024
1 parent 227a194 commit 42ac90b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 17 deletions.
3 changes: 1 addition & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
<head>
<meta charset="utf-8">
<title>ABCD music editor</title>
<script src="https://cdn.jsdelivr.net/npm/ace-builds@1.12.3/src-noconflict/ace.min.js"></script>
<script
src="https://cdn.jsdelivr.net/combine/npm/tone@14.7.58,npm/@magenta/music@1.23.1/es6/core.js,npm/focus-visible@5,npm/html-midi-player@1.5.0"></script>
<script src="https://unpkg.com/tone"></script>
<script src="https://unpkg.com/tone"></script>
<script src="https://cdn.jsdelivr.net/gh/francoisschwarzentruber/textmapeditor@latest/textmapeditor.js"></script>
<script src="https://francoisschwarzentruber.github.io/textmapeditor/textmapeditor.js"></script>
<script src="https://unpkg.com/javascript-lp-solver/prod/solver.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
<link rel="stylesheet" href="lib/abcjs-audio.css" media="all" type="text/css" />
Expand Down
14 changes: 7 additions & 7 deletions js/abcd2abc.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ class ScoreData {

/**
*
* @param {*} line
* @param {*} abcdLine
* @returns false if the line is not a staff line, otherwise returns an object containing the information of the line
* {content: content without the instrument name, instrument: (optional) instrument name}
* @description a staffline is a line starting with a key or starting with an instrument name followed by a key
*/
function isStaffLine(line) {
if (line.startsWith("𝄞") || line.startsWith("𝄢"))
return { content: line };
function isStaffLine(abcdLine) {
if (abcdLine.startsWith("𝄞") || abcdLine.startsWith("𝄢"))
return { content: abcdLine };

const words = line.split(" ");
const words = abcdLine.split(" ");
const firstWord = words[0].toLowerCase();
let content = words.splice(1).join(" ").trim();

Expand All @@ -189,8 +189,8 @@ function isStaffLine(line) {
*
* @returns true if line is of the form "flute {" or "piano { "
*/
function isStaffInstrumentAndOpenCurlyBracket(line) {
const words = line.split(" ");
function isStaffInstrumentAndOpenCurlyBracket(abcdLine) {
const words = abcdLine.split(" ");
const firstWord = words[0].toLowerCase();
const content = words.splice(1).join(" ").trim();

Expand Down
26 changes: 23 additions & 3 deletions js/rhythmguess.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,21 @@ class RhythmGuess {

}

let isDurationMeasureSmallerThanSignatureForSure = false;
//main
try {
const tokens = tokenize(abcdStr);
const elements = addFakeRestIfMeasureIsEmpty(tokenToElements(tokens));
const possibleDurations = computePossibleDurations(elements);
const durationsSolution = await solve(elements.map((e) => e.dhat), possibleDurations, signatureValue);

if (possibleDurations.map((durs) => Math.max(...durs)).reduce((a, b) => a + b, 0) < signatureValue)
isDurationMeasureSmallerThanSignatureForSure = true;

let durationsSolution;
if (possibleDurations.every((durs) => durs.length == 1))
durationsSolution = possibleDurations.map((durs) => durs[0]);
else
durationsSolution = await solve(elements.map((e) => e.dhat), possibleDurations, signatureValue);
setDurations(elements, durationsSolution);
const abcdResult = elementsToABCD(elements, durationsSolution);
console.log("result of the inference: ", durationsSolution, abcdResult)
Expand All @@ -213,7 +222,11 @@ class RhythmGuess {

} catch (e) {
console.error(e);
return abcdStr + ' [Q:"error: inconsistent_rhythm"] ';

if (isDurationMeasureSmallerThanSignatureForSure) // in case of of anacrusis, we do not show an error
return abcdStr;
else
return abcdStr + ' [Q:"error: inconsistent_rhythm"] ';
}
}

Expand Down Expand Up @@ -317,7 +330,7 @@ class NupletSymbolElement {
* @returns an array of possible durations
*/
function getPossibleDurations(element, ratio, signature) {
let A = [eval(signature)]; // the signature itself should always be a possibility (e.g. one single note)
let A = [];
let num = 1;
let istart = 0;

Expand Down Expand Up @@ -363,6 +376,13 @@ function getPossibleDurations(element, ratio, signature) {
for (let i = istart; i < precision; i++)
A.push(num / (2 ** i));

// the signature itself should always be a possibility (e.g. one single note)
if (durationStr == "") {
const signatureEval = eval(signature);
if (A.indexOf(signatureEval) == -1)
A.push(signatureEval);
}

return A.sort((a, b) => Math.abs(a - ratio) - Math.abs(b - ratio));
}

Expand Down
20 changes: 15 additions & 5 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
right: 0px;
bottom: 50%;
left: 0;
border: 1px solid black;
}

#midi {
Expand Down Expand Up @@ -32,12 +33,16 @@

button {
font-size: 18px;
border: 1px solid black;
border: 0px solid black;
border-radius: 7px;
margin: 2px;
padding: 4px;
height: 32px;
background: rgba(0, 0, 0, 0.1);
}

button:hover {
background: rgba(0, 0, 0, 0.2);
}

button:active {
Expand Down Expand Up @@ -121,17 +126,22 @@




#toolbar {
border-radius: 16px;
background: #e4e4ff;
}

.toolbarPart {
background: #DDDDBB;
display: inline-block;
padding: 2px;
margin:3px;
margin: 3px;
border-right: 1px solid;
padding-right: 8px;
}


body {
margin: 0px;
user-select: none; /* Standard syntax */
user-select: none;
/* Standard syntax */
}

0 comments on commit 42ac90b

Please sign in to comment.