Skip to content

Commit

Permalink
Enhancements related to viewing EsAC melodies.
Browse files Browse the repository at this point in the history
  • Loading branch information
craigsapp committed Sep 1, 2024
1 parent 89d23b1 commit f56e745
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
48 changes: 36 additions & 12 deletions _includes/vhv-scripts/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function displayNotation(page, force, restoreid) {
data += "\n";
}
let options = humdrumToSvgOptions();
if (data.match(/CUT[[]/)) {
if (data.match(/^CUT\[/m)) {
options.inputFrom = "esac";
};
if (data.match(/Group memberships:/)) {
Expand Down Expand Up @@ -97,7 +97,7 @@ function displayNotation(page, force, restoreid) {
let ismusedata = false;
if (data.charAt(0) == "<") {
ishumdrum = false;
} else if (data.match(/CUT[[]/)) {
} else if (data.match(/^CUT\[/m)) {
ishumdrum = false;
} else if (data.match(/Group memberships:/)) {
ishumdrum = false;
Expand Down Expand Up @@ -656,16 +656,31 @@ function displayFileTitle(contents) {

function displayFileTitleFromEsac(contents) {
let lines = contents.split(/\r?\n/);
let cut = "";
let cuttitle = "";
let cutincipit = "";
let sig = "";
let keyid = "";
let collection = "";

let matches;

matches = contents.match(/CUT\[\s*(.*?)\s*\]/s);
if (matches) {
let lines = matches[1].split(/\r?\n/);
if (lines.length == 1) {
cuttitle = lines[0].replace(/\s+$/, "");
} else if (lines.length > 1) {
cuttitle = lines[0].replace(/\s+$/, "");
cutincipit = lines[1].replace(/^\s+/, "");
} else {
cuttitle = "";
cutincipit = "";
}
}


for (let i=0; i<lines.length; i++) {
if (matches = lines[i].match(/^CUT\[(.*)\]\s*$/)) {
cut = matches[1];
} else if (matches = lines[i].match(/^SIG\[(.*)\]\s*$/)) {
if (matches = lines[i].match(/^SIG\[(.*)\]\s*$/)) {
sig = matches[1];
} else if (matches = lines[i].match(/^KEY\[(.*)\]\s*$/)) {
let allkey = matches[1];
Expand All @@ -686,15 +701,21 @@ function displayFileTitleFromEsac(contents) {
title = sig + ": ";
}
}
if (title !== "") {
title += " ";
if (cuttitle !== "") {
title += ` ${cuttitle}`;
}
if (cut !== "") {
title += cut;
if (cutincipit !== "") {
if (cuttitle !== "") {
title += ` <span style="color:gray">(<i>${cutincipit}</i>)</span>`;
} else {
title += `<i>${cutincipit}</i>`;
// treat as title
}
}
title = title.replace(/ - /g, " &ndash; ");
// DWOK06 K0598:
title = title.replace("�", "ł", "g");
// There can be this character in titles: �, it represents
// an accented letter, but which one is unknown.

let tarea;
tarea = document.querySelector("#title");
Expand Down Expand Up @@ -765,6 +786,8 @@ function displayIndex(directory, options) {
//
// replaceEditorContentWithHumdrumFile -- If the editor contents is
// MusicXML, then convert to Humdrum and display in the editor.
// If it is EsAC data, then extract one EsAC file near cursor to
// convert to Humdrum.
//

function replaceEditorContentWithHumdrumFile(text, page) {
Expand Down Expand Up @@ -793,9 +816,10 @@ function replaceEditorContentWithHumdrumFile(text, page) {
// this is MEI data
options = meiToHumdrumOptions();
meiQ = true;
} else if (text.slice(0, 1000).match(/CUT[[]/)) {
} else if (text.slice(0, 1000).match(/^CUT\[/m)) {
// EsAC data
options = esacToHumdrumOptions();
text = getCurrentEsacMelody();
} else {
// don't know what it is, but probably Humdrum
alert("Cannot convert data to Humdrum");
Expand Down
5 changes: 5 additions & 0 deletions _includes/vhv-scripts/utility-ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ function toggleEditorMode() {

function showIdInEditor(id) {
if (EditorMode == "xml") {
// MusicXML data has no IDs so cannot use this function
return;
}
if (EditorMode == "esac") {
// EsAC data has no IDs so cannot use this function
return;
}
var matches = id.match(/-[^-]*L(\d+)/);
Expand Down

0 comments on commit f56e745

Please sign in to comment.