Skip to content

Commit

Permalink
add (alt-)k/K keyboard commands to add/remove next/previous system br…
Browse files Browse the repository at this point in the history
…eak.
  • Loading branch information
craigsapp committed Jun 5, 2024
1 parent 985d373 commit 3c586ee
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 2 deletions.
57 changes: 57 additions & 0 deletions _includes/vhv-scripts/editor/addSystemBreakToNextBarline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{% comment %}
//
// Programmer: Craig Stuart Sapp <[email protected]>
// Creation Date: Wed Jun 5 02:08:33 PDT 2024
// Last Modified: Wed Jun 5 02:08:40 PDT 2024
// Filename: addSystemBreakToNextBarline.js
// Web Address: https://verovio.humdrum.org/scripts/addSystemBreakToNextBarline.js
// Syntax: JavaScript 1.8/ECMAScript 5
// vim: ts=3: ft=javascript
//
// Description: Add a system break to the next barline (or remove break if
// there is already one).
//
{% endcomment %}


function addSystemBreakToNextBarline() {
let location = EDITOR.getCursorPosition();
let index = location.row;

var contents = getTextFromEditor().split(/\r?\n/);

let barIndex = -1;
for (let i=index; i<contents.length; i++) {
if (contents[i].match(/^=/)) {
barIndex = i;
break;
}
}
if (barIndex < 1) {
return;
}

console.warn("LO", contents[barIndex - 1]);

if (contents[barIndex-1].match(/^!!LO:[LP]B:/)) {
// Remove system break line
var Range = ace.require("ace/range").Range;
var range = new Range(barIndex-1, 0, barIndex, 0);
EDITOR.session.remove(range);
return;
}

let text = "!!LO:LB:g=original";
let textIndex = barIndex - 1;
EDITOR.session.insert({ row: textIndex + 1, column: 0 }, text + '\n');

// Adjust the cursor position if it is below the inserted line
// if (cursorPosition.row >= lineNumber) {
// cursorPosition.row += 1;
// }

EDITOR.moveCursorToPosition(location);
}



56 changes: 56 additions & 0 deletions _includes/vhv-scripts/editor/addSystemBreakToPreviousBarline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{% comment %}
//
// Programmer: Craig Stuart Sapp <[email protected]>
// Creation Date: Wed Jun 5 02:08:33 PDT 2024
// Last Modified: Wed Jun 5 02:08:40 PDT 2024
// Filename: addSystemBreakToPreviousBarline.js
// Web Address: https://verovio.humdrum.org/scripts/addSystemBreakToPreviousBarline.js
// Syntax: JavaScript 1.8/ECMAScript 5
// vim: ts=3: ft=javascript
//
// Description: Add a system break to the next barline (or remove break if
// there is already one).
//
{% endcomment %}


function addSystemBreakToPreviousBarline() {
let location = EDITOR.getCursorPosition();
let index = location.row;

var contents = getTextFromEditor().split(/\r?\n/);

let barIndex = -1;
for (let i=index; i>=1; i--) {
if (contents[i].match(/^=/)) {
barIndex = i;
break;
}
}
if (barIndex < 1) {
return;
}

console.warn("LO", contents[barIndex - 1]);

if (contents[barIndex-1].match(/^!!LO:[LP]B:/)) {
// Remove system break line
var Range = ace.require("ace/range").Range;
var range = new Range(barIndex-1, 0, barIndex, 0);
EDITOR.session.remove(range);
location.row--;
EDITOR.moveCursorToPosition(location);
return;
}

let text = "!!LO:LB:g=original";
let textIndex = barIndex - 1;
EDITOR.session.insert({ row: textIndex + 1, column: 0 }, text + '\n');
location.row++;
EDITOR.moveCursorToPosition(location);
}





2 changes: 2 additions & 0 deletions _includes/vhv-scripts/editor/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ var InterfaceSingleNumber = 0;
{% include vhv-scripts/editor/addDataLineAboveCurrentPosition.js %}
{% include vhv-scripts/editor/addBarlineAboveCurrentPosition.js %}
{% include vhv-scripts/editor/addInvisibleBarlineAboveCurrentPosition.js %}
{% include vhv-scripts/editor/addSystemBreakToNextBarline.js %}
{% include vhv-scripts/editor/addSystemBreakToPreviousBarline.js %}
{% include vhv-scripts/editor/createNullLine.js %}
{% include vhv-scripts/editor/addNullLine.js %}
{% include vhv-scripts/editor/addSpineToRight.js %}
Expand Down
21 changes: 19 additions & 2 deletions _includes/vhv-scripts/listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,15 @@ function processNotationKeyCommand(event) {
}
break;

// case KEYS.KKey:
case KEYS.KKey:
if (event.shiftKey) {
addSystemBreakToPreviousBarline();
event.preventDefault();
} else {
addSystemBreakToNextBarline();
event.preventDefault();
}
break;

case KEYS.LKey:
if (event.shiftKey) {
Expand Down Expand Up @@ -743,7 +751,16 @@ function processInterfaceKeyCommand(event) {
case KEYS.JKey: // UNUSED
break;

case KEYS.KKey: // UNUSED
case KEYS.KKey:
if (event.altKey) {
if (event.shiftKey) {
addSystemBreakToPreviousBarline();
event.preventDefault();
} else {
addSystemBreakToNextBarline();
event.preventDefault();
}
}
break;

case KEYS.LKey: // toggle color of staff layers
Expand Down

0 comments on commit 3c586ee

Please sign in to comment.