Setting chordStyle for a Score created from the API
Hi,
When creating a score in a plugin with the following code:
var score = newScore("Workout", "bass-flute", 99);
the chordStyle
setting isn't set correctly (this can be verified when adding a Chord diagram to a segment: the chord isn't displayed as it does. See this question for more info).
My question is
* how to create the score directly with the chordStyle
set correclty
* - or - how to change it afterwards from the plugin ?
My attempts to modify it from the code failed so far.
Both this:
var score = newScore("Workout", "bass-flute", 1);
var cs=eval("Sid.chordStyle");
console.log("CHORD STYLE:" + score.styles.value(cs));
and this:
var score = newScore("Workout", "bass-flute", 1);
console.log("CHORD STYLE:" + score.styles.value(Sid.chordStyle));
are returning an error that "Sid" is unknown.
Any suggestion on how to have this chordStyle
set correctly ?
Thanks
Comments
As far as I can see
score.style.value()
takes a string (andstyle
is singular)(or
jazz
orcustom
)In reply to As far as I can see score… by Jojo-Schmitz
My mistake for the syntax. Thanks.
However, that doesn't solve the problem.
In this newly created score, can you add a note, and add a chord (CTRL+K) with the following text "Bbt7" ?
For me, it is displayed as "t7". Do you have the same behaviour ?
In reply to My mistake for the syntax… by parkingb
Haven't tried.
What style is it set to then?
In reply to Haven't tried. What style is… by Jojo-Schmitz
By default, the command returns "std" (for a newly created score, and an empty string for a previously-opened score).
After setting to "jazz", it returns "jazz".
But the score itself is still behaving incorrectly until I go in the Score styles and set it manually.
In reply to By default, the command… by parkingb
How did you manage to set it? I failed on that.
You can change styles by plugin with style.setValue()
https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…
In reply to You can change styles by… by sammik
var score = newScore("Workout", "bass-flute", 1);
console.log("CHORD STYLE:" + score.style.value("chordStyle"));
curScore.style.setValue("chordStyle","jazz");
console.log("CHORD STYLE:" + score.style.value("chordStyle"));
The output is:
Debug: CHORD STYLE:std
Debug: CHORD STYLE:jazz
But in the end, a "Bbt7" chord is still displayed as "t7".
In reply to var score = newScore(… by parkingb
I've never tried setting this via a plugin, but internally, the effect of that style setting is to cause a particular XML file to be loaded (chords_std or chord_jazz). The symptoms you describe are consistent with that load not happening. Not sure what might be required to trigger it, perhaps wrapping in stand/end command statements?
In reply to I've never tried setting… by Marc Sabatella
> perhaps wrapping in stand/end command statements?
This is already the case.
And actually, setting that style's value is only a workaround because the score creation via a plugin does not do it correctly.
But the explanation could be the same: the score creation wouldn't load the default xml file correctly.
In reply to > perhaps wrapping in stand… by parkingb
The style dialog seems to change several style values when you change chord style settings (https://github.com/musescore/MuseScore/blob/3.x/mscore/editstyle.cpp#L1…). Plugin API certainly doesn't do that implicitly, so perhaps you also need to change both
chordStyle
andchordDescriptionFile
settings in your plugin (to values"jazz"
and"chords_jazz.xml"
correspondingly).In reply to > perhaps wrapping in stand… by parkingb
Are you forcing a layout of the score on creation? That's when this might normally get triggered.
In reply to Are you forcing a layout of… by Marc Sabatella
No I don't. I just do
newScore("Workout", "bass-flute", 1)
In reply to var score = newScore(… by parkingb
Interesting I'm sure I tried exactly and it didn't work. It does now though.
But indeed that change is not taken unless/until I open the style dialog (without any change to it)
In reply to Interesting I'm sure I tried… by Jojo-Schmitz
That would be because the code executed on closing the style dialog notices that chord style has been changed and thus automatically loads the correct file. This is what a plugin would need to emulate, as Dmitri mentions above.
In reply to Interesting I'm sure I tried… by Jojo-Schmitz
Any idea how to resolve this from the API ? Or a workaround ?
I was thinking to set the
chordDescriptionFile
to one of default xml file, but I'm not able to retrieve the right filepath within the plugin.In reply to Any idea how to resolve this… by parkingb
Sorry, I'm not familiar enough with the plugin API to offer suggestions.
In reply to Any idea how to resolve this… by parkingb
You don't need a full file path, just
chords_std.xml
orchords_jazz.xml
would be enough. The code below does change a chord style for me:Actually the second line alone produces the effect of changing a chord style but it's better to set both values to avoid chord style settings being reverted back by the style dialog, like Jojo has mentioned above.
In reply to You don't need a full file… by dmitrio95
Thanks !!
For setting the "std" style, oddly one has to set the jazz style first and then the std one:
In reply to Thanks !! For setting the … by parkingb
The reason is that likely the std style is already active (though incomplete) and setting it to the same value doesn't do anything (the actual setting is not applied then).
So many discussions on so many topics, but I'm glad my new plugin is ready: Scale Workout Builder.
Feel free to check it here. Thanks to all for your help.