abcjs-music / obsidian-plugin-abcjs

Plugin which renders music notations from code blocks
190 stars 14 forks source link

Once tablature mode is entered in a note, it can't be exited #32

Open miesvanderrobot opened 1 year ago

miesvanderrobot commented 1 year ago

Loving the tablature support, especially since it supports capos and alternate tunings, which means I can actually support my tenor guitar!

Ran into an issue, though. Once tablature occurs within a note, it ends up applying the same tablature properties to all subsequent non-tablature music-abc blocks in the same note. Here's an example:

X:1
T:The Legacy Jig (just fine)
M:6/8
L:1/8
R:jig
K:G
GFG BAB | gfg gab | GFG BAB | d2A AFD |
GFG BAB | gfg gab | age edB |1 dBA AFD :|2 dBA ABd |:
efe edB | dBA ABd | efe edB | gdB ABd |
efe edB | d2d def | gfe edB |1 dBA ABd :|2 dBA AFD |]
{
  "tablature": [{
    "instrument": "mandolin", 
    "label": "Tenor Guitar (%T)", 
    "tuning": ["C,", "G,", "D", "A"],
    "highestNote": "e'",
    "capo": "2"
  }]
}
---
X:1
T: Cooley's
M: 4/4
L: 1/8
R: reel
K: G
|:D2|EB{c}BA B2 EB|~B2 AB dBAG|FDAD BDAD|FDAD dAFD|
X:1
T:The Legacy Jig (now in tablature)
M:6/8
L:1/8
R:jig
K:G
GFG BAB | gfg gab | GFG BAB | d2A AFD |
GFG BAB | gfg gab | age edB |1 dBA AFD :|2 dBA ABd |:
efe edB | dBA ABd | efe edB | gdB ABd |
efe edB | d2d def | gfe edB |1 dBA ABd :|2 dBA AFD |]
controlledaccident commented 1 year ago

Tabs seem to be applied to all other notes as well, until Obsidian restart

alensiljak commented 1 year ago

Do you mean it applies to all abc code blocks only?

controlledaccident commented 1 year ago

All abc blocks, in all notes in the vault, if a note with tab code is open/opened.

miesvanderrobot commented 1 year ago

This one looks correct in HTML. I'm guessing that somehow in your implementation (or the specific implementation you've chosen to consume, as I'm not using a node module here), a variable containing the tablature details isn't getting reinitialized when it should.


<html>
<head>
    <style>

    </style>
    <script src="/scripts/snippet-javascript-console.min.js?v=1"></script>
</head>
<body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/abcjs/6.2.2/abcjs-basic-min.js" integrity="sha512-KXKtG2UKjAKEEwwKKNioYwVHGm/gH0ZmME+ePGFwbjs4Banx6+xJVtDpC2A2QM9nGtamOP4tqEYfxloLjq3XcA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<div id="music">
X:1
T:The Legacy Jig (just fine)
M:6/8
L:1/8
R:jig
K:G
GFG BAB | gfg gab | GFG BAB | d2A AFD |
GFG BAB | gfg gab | age edB |1 dBA AFD :|2 dBA ABd |:
efe edB | dBA ABd | efe edB | gdB ABd |
efe edB | d2d def | gfe edB |1 dBA ABd :|2 dBA AFD |]
</div>
    <script type="text/javascript">
        ABCJS.renderAbc("music", $("#music").text());
    </script>
<div id="music2">
X:1
T: Cooley's
M: 4/4
L: 1/8
R: reel
K: G
|:D2|EB{c}BA B2 EB|~B2 AB dBAG|FDAD BDAD|FDAD dAFD|
</div>
    <script type="text/javascript">
        ABCJS.renderAbc("music2", $("#music2").text(), {
        "tablature": [{
        "instrument": "mandolin", 
        "label": "Tenor Guitar (%T)", 
        "tuning": ["C,", "G,", "D", "A"],
        "highestNote": "e"
    }]
});
</script>
<div id="music3">
X:1
T:The Legacy Jig (now in tablature)
M:6/8
L:1/8
R:jig
K:G
GFG BAB | gfg gab | GFG BAB | d2A AFD |
GFG BAB | gfg gab | age edB |1 dBA AFD :|2 dBA ABd |:
efe edB | dBA ABd | efe edB | gdB ABd |
efe edB | d2d def | gfe edB |1 dBA ABd :|2 dBA AFD |]
</div>
<script type="text/javascript">
    ABCJS.renderAbc("music3", $("#music3").text());
</script>      
</body>
</html>```
alensiljak commented 1 year ago

Looking at https://github.com/abcjs-music/obsidian-plugin-abcjs/blob/main/playback_element.ts, I see nothing obvious that could be adjusted. Based on the issue description I'd assume that the plugin settings (i.e. tablatures) apply to all the instances. If that is true, it is not obviously clear what the solution would be. Checking the Obsidian docs for any hints on the available options would be my first step.