Skip to content

Commit

Permalink
Added page break option for setlists
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-Pearson committed Nov 30, 2018
1 parent 952d491 commit fc8919f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 74 deletions.
33 changes: 26 additions & 7 deletions scripts/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ function preProcessABC(inABC)
// include the users selected cleff
let keyText = GetABCHeader(inABC, 'K');

console.log(keyText);

let modifiedABC = SetABCHeader(inABC, 'K', keyText + " " + Settings.cleff);

return modifiedABC;
Expand Down Expand Up @@ -361,8 +359,7 @@ function OnPDFSettingChanged()

function CreatePDF(tunes, callback)
{
var remainingTunes = tunes.length;

var remainingTunes = 1;
var tuneData = [];

tunes.forEach(function(tune, index) {
Expand All @@ -371,6 +368,13 @@ function CreatePDF(tunes, callback)
abc: ''
});

if(tune.startsWith("pagebreak"))
{
return;
}

remainingTunes++;

LoadRawABC(tune, function(abc) {
tuneData[index].abc = abc;

Expand All @@ -385,18 +389,22 @@ function CreatePDF(tunes, callback)
});

remainingTunes--;

if(remainingTunes == 0)
{
CreatePDFFromTuneData(tuneData, callback);

//clean up the created elements
tuneData.forEach(function(data) {
document.body.removeChild(data.svg);
if(data.svg != undefined)
{
document.body.removeChild(data.svg);
}
});
}
});
});

remainingTunes--;
}

function CreatePDFFromTuneData(tuneData, callback)
Expand All @@ -418,7 +426,18 @@ function CreatePDFFromTuneData(tuneData, callback)
doc.addPage();

let yOffset = PDFTopMargin;
tuneData.forEach(function(data) {
tuneData.forEach(function(data, idx) {
if(data.path.startsWith("pagebreak"))
{
if(yOffset != PDFTopMargin)
{
doc.addPage();
yOffset = PDFTopMargin;
}

return;
}

if(yOffset + (data.svg.clientHeight * PDFNoteSize) >= 750)
{
doc.addPage();
Expand Down
104 changes: 40 additions & 64 deletions scripts/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ function OnTuneIndexLoaded()
$("#lbl-num-in-set").html(CurSet.length);
$("#lbl-num-in-set").show();

var setlist = $("#setlist");
setlist.html("");

var setTemplate = function(tune) {
return `<li class="list-group-item setlist-item">
<a href="javascript:void(0);" onclick="MoveTuneUp('${tune.filename}', $(this));" class="moveupbtn"><button type="button" class="btn btn-outline-dark" style="padding-bottom:1px;"><i class="fas fa-sort-up"></i></button></a>
<a href="javascript:void(0);" onclick="MoveTuneDown('${tune.filename}', $(this));" class="movedownbtn"><button type="button" class="btn btn-outline-dark" style="padding-top:1px;"><i class="fas fa-sort-down"></i></button></a>
<span class="setlist-title">${tune.title}</span>
<a class="setlist-remove" href="javascript:void(0);" onclick="RemoveFromSetClicked('${tune.filename}', $(this))"><i class="fas fa-trash-alt"></i></button>
</li>`;
};

try
{
LocalSet = JSON.parse(decodeURIComponent(getHTMLParam("set", "")));
Expand All @@ -36,77 +24,52 @@ function OnTuneIndexLoaded()
history.replaceState(null, null, "set.html");
}

LocalSet.forEach(function(tunefilename) {
let tuneData = GetTuneData(tunefilename);

let removeBtn = setlist.append(setTemplate(tuneData)).find(".setlist-remove");
removeBtn[0].addEventListener('mousedown', function(event) {
event.stopPropagation();
});
});

if(LocalSet.length == 0)
{
$("#set-cotnainer").hide();
$(".no-tunes-found").show();
}

OnSetListChanged();
}

function OnSetListChanged()
{
return;
let container = $("#setlist-music-container");
var setlist = $("#setlist");
setlist.html("");

var setTemplate = function(filename, title) {
return `<li class="list-group-item setlist-item">
<a href="javascript:void(0);" onclick="MoveTuneUp('${filename}', $(this));" class="moveupbtn"><button type="button" class="btn btn-outline-dark" style="padding-bottom:1px;"><i class="fas fa-sort-up"></i></button></a>
<a href="javascript:void(0);" onclick="MoveTuneDown('${filename}', $(this));" class="movedownbtn"><button type="button" class="btn btn-outline-dark" style="padding-top:1px;"><i class="fas fa-sort-down"></i></button></a>
<span class="setlist-title">${title}</span>
<a class="setlist-remove" href="javascript:void(0);" onclick="RemoveFromSetClicked('${filename}', $(this))"><i class="fas fa-trash-alt"></i></button>
</li>`;
};

if(LocalSet.length == 0)
{
conainer.html("");
container.hide();
setlist.hide();
$(".no-tunes-found").show();
return;
}
else
{
container.show();
setlist.show();
$(".no-tunes-found").hide();
}

container.html("<i class=\"fas fa-spinner fa-2x fa-spin\"></i>");

let numTunes = LocalSet.length;
let abcs = [];

LocalSet.forEach(function(tune, index) {
LoadRawABC(tune, function(abc) {
abcs.splice(index, 0, abc);
numTunes--;

// check if all requests have returned
if(numTunes == 0)
{
let superABC = "";
let containers = [];

container.html("");

abcs.forEach(function(tuneABC, index) {
tuneABC = SetABCHeader(tuneABC, "X", index+1);
superABC = superABC + "\n" + tuneABC;
LocalSet.forEach(function(tunefilename, idx) {
if(tunefilename.startsWith("pagebreak"))
{
LocalSet[idx] = "pagebreak" + idx;
let removeBtn = setlist.append(setTemplate("pagebreak" + idx, "New Page")).find(".setlist-remove");

container.append("<div></div>");
containers.push(container[0].children[index]);
});
removeBtn[0].addEventListener('mousedown', function(event) {
event.stopPropagation();
});
return;
}

console.log(superABC);
let tuneData = GetTuneData(tunefilename);

ABCJS.renderAbc(containers, superABC,
{ },
{
staffwidth: container.width() - 30,
},
{ });
}
let removeBtn = setlist.append(setTemplate(tuneData.filename, tuneData.title)).find(".setlist-remove");
removeBtn[0].addEventListener('mousedown', function(event) {
event.stopPropagation();
});
});
}
Expand Down Expand Up @@ -177,3 +140,16 @@ function MoveTuneUp(tune, element)
SetCookie(CurSet_CNAME, JSON.stringify(CurSet), CDUR);
}
}

function AddPageBreak()
{
LocalSet.push("pagebreak");

if(!usingParameterSet)
{
CurSet = LocalSet;
SetCookie(CurSet_CNAME, JSON.stringify(CurSet), CDUR);
}

OnSetListChanged();
}
3 changes: 2 additions & 1 deletion set.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ <h1>My Set</h1>
<p id="msg-parameterset" style="display:none;">You are viewing a shared set, to view your own set reload the page</p>
<a href="javascript:void(0);" onclick="GetSharableLink();"><button type="button" class="btn btn-outline-dark"><i class="fas fa-share-alt"></i> Share</button></a>
<a href="javascript:void(0);" onclick="CreateSetPDF();"><button type="button" class="btn btn-outline-dark"><i class="fas fa-file-pdf"></i> Create Printout</button></a>
<a href="javascript:void(0);" onclick="AddPageBreak();"><button type="button" class="btn btn-outline-dark"><i class="fas fa-plus-circle"></i> Add page break</button></a>

<p>Click the arrow buttons on a tune to change it's order the set</p>
<ul class="list-group" id="setlist">
<li class="list-group-item"><i class="fas fa-spinner fa-2x fa-spin"></i></li>
<i class="fas fa-spinner fa-2x fa-spin"></i>
</ul>
</div>
<div class="no-tunes-found">
Expand Down
2 changes: 1 addition & 1 deletion tunes/kingofthefairies.abc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ r: 32
|: B,2 | "Em" E>DE>F G>FG>A | "Em" B2 B>A G>FG>A | "Em" B2 E2 E>FG>E | "D" F>GF>E D2 B,2 |
"Em" E>DE>F G>FG>A | "Em" B>AG>B "D" d3 =c | "Em" B2 E2 "D" G>FE>D | "Em" E2 E>D E2 :|
B2 | "Em" e2 e2 B>de>f | "Em" g>ag>f e3 f | "Em" e2 B2 B>AB>c | "D" d>ed>c B>c (3dcB |
"Em" e2 B2 B>de>f | "Em" g>ag>f e>fe>d | "Em" B>de>g "D" f>ed>f | "Em" e2 e>d e2 e>f |
"Em" e2 B2 B>de>f | "Em" g>ag>f e3 f | "Em" g>f (3efg "D" f>e (3def | "Em" e2 e>d e2 e>f |
"Em" g3 e "D" f3 d | "Em" e>dB>c d3 e | "D" d>BA>F G>AB>c | "D" d>BA>F G>FE>D |
"Em" B,2 E2 E>FG>A | "Em" B2 e2 e>de>f | "Em" e2 B2 "D" B>AG>F | "Em" E2 E>D E2 |]
2 changes: 1 addition & 1 deletion tunes/outontheocean.abc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ L: 1/8
K: Gmaj
Z: ABC transcription by Verge Roller
r: 32
|: FE | "G" D2 B BAG | "G" BdB "D" ABA | "G" GED G2 A | "G" BcB "D" AGE |
|: FE | "G" D2 B BAG | "G" BdB "D" ABA | "G" GED G2 A | "G" BdB "D" AGE |
"G" D2 B BAG | "G" BdB "D" ABA | "G" GED G2 A | "G" BGG G :|
|: Bd | "Em" e2 e edB | "Em" e2 e edB | "Bm7" d2 d def | "C" gfe "D" dBA |
"G" G2 A B2 d | "C" ege "D" dBA | "G" GED G2 A | "G" BGG G:|

0 comments on commit fc8919f

Please sign in to comment.