Skip to content

Commit

Permalink
fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
cat2151 committed Jan 4, 2024
1 parent 14c0a7c commit d8c4d40
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
4 changes: 2 additions & 2 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<div id="music-score"></div>
<textarea readonly id="abc-notation"></textarea>
<script defer src="https://cdn.jsdelivr.net/npm/abcjs@6/dist/abcjs-basic-min.min.js"></script>
<script defer src="https://cdn.jsdelivr.net/gh/cat2151/easyabcjs6/easyabcjs6.js"></script>
<script defer src="https://cdn.jsdelivr.net/gh/cat2151/easyabcjs6@0/easyabcjs6.js"></script>
<script defer type="module">
import { SyntaxError, parse } from "./mml2abc.mjs";
window.mml2abc = { SyntaxError, parse };
</script>
<script defer src="https://cdn.jsdelivr.net/gh/cat2151/easymmlabc/easymmlabc.js"></script>
<script defer src="https://cdn.jsdelivr.net/gh/cat2151/easymmlabc@0/easymmlabc.js"></script>
<script defer src="./main.js"></script>
<a href="https://github.com/cat2151/mml2abc/">GitHub</a>
</body>
Expand Down
17 changes: 16 additions & 1 deletion dist/mml2abc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
if (denominator == 1) denominator = "";
return {numerator, denominator};
}
function updateSharpFlats(pitch, sharp, flat, sharpFlats) {
let iPitch = "abcdefg".indexOf(pitch);
sharpFlats[iPitch] = sharp.length - flat.length;
}

function peg$subclass(child, parent) {
function C() { this.constructor = child; }
Expand Down Expand Up @@ -375,7 +379,17 @@ function peg$parse(input, options) {
isNewLineTop = true;
return `${prefix}V:${track}\n`; };
var peg$f16 = function(pitch, sharp, flat) {
pitch = sharp.join('') + flat.join('') + pitch;
// sharp, flat, natural
const oldSharpFlat = sharpFlats["abcdefg".indexOf(pitch)];
updateSharpFlats(pitch, sharp, flat, sharpFlats);
const isNatural = (!sharp.length) && (!flat.length);
if (isNatural && oldSharpFlat) {
pitch = "=" + pitch; // こうしないと前回の臨時記号が適用されるので(五線譜と同じ)
} else {
pitch = sharp.join('') + flat.join('') + pitch;
}

// octave
switch (octave) {
case 0: return pitch.toUpperCase() + ',,,,,';
case 1: return pitch.toUpperCase() + ',,,,';
Expand Down Expand Up @@ -1282,6 +1296,7 @@ function peg$parse(input, options) {
let chordOctave = null;
let chordAbcNoteLength = null;
let isStaccato = false;
let sharpFlats = [0,0,0,0,0,0,0]; // 並びはabcdefg

peg$result = peg$startRuleFunction();

Expand Down
17 changes: 16 additions & 1 deletion peggyjs/mml2abc.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
if (denominator == 1) denominator = "";
return {numerator, denominator};
}
function updateSharpFlats(pitch, sharp, flat, sharpFlats) {
let iPitch = "abcdefg".indexOf(pitch);
sharpFlats[iPitch] = sharp.length - flat.length;
}
}}
{
let track = 1;
Expand All @@ -38,6 +42,7 @@
let chordOctave = null;
let chordAbcNoteLength = null;
let isStaccato = false;
let sharpFlats = [0,0,0,0,0,0,0]; // 並びはabcdefg
}
MMLs=mmls:MML* { return "V:1\n" + mmls.join(''); }
MML=NOTE /REST
Expand Down Expand Up @@ -172,7 +177,17 @@ TRACK_SEPARATOR=_ ";" _ {
return `${prefix}V:${track}\n`; }
PITCH=pitch:[a-g] sharp:SHARP* flat:FLAT* {
pitch = sharp.join('') + flat.join('') + pitch;
// sharp, flat, natural
const oldSharpFlat = sharpFlats["abcdefg".indexOf(pitch)];
updateSharpFlats(pitch, sharp, flat, sharpFlats);
const isNatural = (!sharp.length) && (!flat.length);
if (isNatural && oldSharpFlat) {
pitch = "=" + pitch; // こうしないと前回の臨時記号が適用されるので(五線譜と同じ)
} else {
pitch = sharp.join('') + flat.join('') + pitch;
}
// octave
switch (octave) {
case 0: return pitch.toUpperCase() + ',,,,,';
case 1: return pitch.toUpperCase() + ',,,,';
Expand Down
17 changes: 16 additions & 1 deletion src/mml2abc.commonjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions test/mml2abc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,11 @@ describe("mml2abc", () => {
test("bar", () => {
expect(parse("/*|*/")).toEqual(prefix + '|');
});
test("臨時記号。ABCは臨時記号が小節内で維持される。五線譜と同じ。MMLとは違う。そこを対策する用", () => {
expect(parse("l8c+c")).toEqual(prefix + '^C=C');
});
test("臨時記号", () => {
expect(parse("l8f+f+fff+f+d+dd+g-g-ggg-g-")).toEqual(prefix + '^F^F=FF^F^F^D=D^D_G_G=GG_G_G');
});

});

0 comments on commit d8c4d40

Please sign in to comment.