abcjs-music / obsidian-plugin-abcjs

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

Choosing Instrument Voice #37

Closed controlledaccident closed 1 year ago

controlledaccident commented 1 year ago

I'm trying to display and edit very simple rhythms using the plugin.

I've been going round and round in circles from abcjs (https://paulrosen.github.io/abcjs/) > abcnotation (https://abcnotation.com/) trying to find out how to change the instrument voice (i.e. the synthesized sound).

Are standard GM MIDI voices available? How does one choose them (the syntax) inside the abc-music code block?

V:p1 perc in the header gets me percussion, but what about other instruments?

Please, any help much appreciated.

Many thanks

alensiljak commented 1 year ago

In the mapping sample for the drums, I have:

%%MIDI channel 10
%%MIDI program 0

%%MIDI drummap  E 35 % acoustic bass drum

% percmap $VISUAL-PLACEMENT $STD-NAME [ $NOTE-HEAD ]
%%percmap E  bass-drum-1

This syntax is supported by abcjs. More can probably be found in the abcjs code by searching for these keywords. The Obsidian plugin, however, was initially intended for simple snippets of musical notes inside a markdown note. Anything beyond that is a stretch as Obsidian is a note taking application. I'd suggest that you go through the source code in this repository. There is really only three TypeScript files (used to be just one as the plugin is fairly simple). It should not be too difficult to understand what it does. I think that configuration options were exposed when the audio was added recently.

alensiljak commented 1 year ago

Some options are available at https://configurator.abcjs.net/audio/ For more info, it would probably make more sense to look at the abcjs resources (repository, forums, reddit, etc.). I've used only the features that relate to drums.

alensiljak commented 1 year ago

i.e. https://github.com/paulrosen/abcjs/issues/919

alensiljak commented 1 year ago

More resources: https://music.meta.stackexchange.com/questions/2782/documentation-for-abcjs

controlledaccident commented 1 year ago

Ah ok. Many thanks! Now we're talking.

V:1
%%MIDI program 0

That's it — all I needed. I'm not trying to write a symphony here — just trying to make some very quick notes — rhythms to clap... got distracted trying to change the voice, and stubborn as I am, I spent so much time looking around the web I felt a complete fool for not just using a pencil and paper.

I was playing around with the abcjs Configurator yesterday but had no clue how to convert the JS:

abcjs.renderMidi(
    "midi-id",
    abcString,
    {
        program: 99,
    });

into something which works in the music-abc code block.

Thanks

alensiljak commented 1 year ago

OK, good to know. I don't think there's anything too complicated around abcjs. Things may at times not be very well documented for new features but that is only due to the fact that Paul is the only one adding features and maintaining everything related to the library, so there may be a delay due to the time availability.

In the case above, my understanding is that the options in the curly braces can be passed to the Obsidian plugin. If you look at https://github.com/abcjs-music/obsidian-plugin-abcjs#custom-options you may see how to pass options. The %% instruction is practical as it stays in the tune code itself.

As for the code sample above, I don't think there is a renderMidi function or the program option but I may be wrong.

alensiljak commented 1 year ago

https://github.com/abcjs-music/obsidian-plugin-abcjs/blob/main/playback_element.ts

Contains all the code that relates to the initialisation and activation of abcjs and the MIDI output.

controlledaccident commented 1 year ago
V:1
%%MIDI program 0

It works, but it's not a "JSON string at the top of the code block" which is why I'm still baffled.

controlledaccident commented 1 year ago

As for the code sample above, I don't think there is a renderMidi function or the program option but I may be wrong.

abcjs.renderMidi(
    "midi-id",
    abcString,
    {
        program: 99,
    });

is from the abcjs configurator https://configurator.abcjs.net/audio/. The object in the function updates when you insert a value in the Instrument number (program) field.

And so I assumed it might have something to do with changing the voice (perhaps the contents of this elusive JSON)

controlledaccident commented 1 year ago

V:p1 perc

I haven't found any reference to this abbreviation perc anywhere else other than that example in 4.6 of the abc notation documentation where I copied it from:

V:p1 perc stafflines=3 m=C mozart:noteC=snare-drum (https://abcnotation.com/wiki/abc:standard:v2.1)

So no idea why but it also works...

controlledaccident commented 1 year ago

OK, good to know. I don't think there's anything too complicated around abcjs.

Yes, I'm here as a Obsidian user primarily though, and it seems like a very useful plugin, but I'm no pro developer.

I have some basic, rusty coding knowledge so I assumed it wouldn't be beyond me, and it's not... but what may seem totally obvious to some probably isn't to me.

Thanks for your input

alensiljak commented 1 year ago

but I'm no pro developer

https://www.youtube.com/watch?v=TK1mBqKvIyU

See at least the first 5 minutes.

controlledaccident commented 1 year ago

https://www.youtube.com/watch?v=TK1mBqKvIyU

See at least the first 5 minutes.

What am I to infer, or what would you like me to infer, exactly from the first minutes of this video? I see many topics raised. Many thanks

alensiljak commented 1 year ago

What am I to infer, or what would you like me to infer, exactly from the first minutes of this video?

Not being a pro developer does not mean you're prohibited from learning and coding. :)

controlledaccident commented 1 year ago

Not being a pro developer does not mean you're prohibited from learning and coding

Ah right, perhaps that's why I've spent hours over the last few days reading through Javascript library documentation, abc notation documentation, and sifting through source code of an unfamiliar language, learning how to use abc notation and this plugin, when I could have been... I dunno... walking in the woods or something.

Who'd have thunk it. Thanks for clearing that up. :) :)

controlledaccident commented 1 year ago

Any chance you could share a working example of your drums inside the plugin?

Any chance you could share an example of passing an option(s) (not tablature) using a JSON at the top of the code block inside the plugin? Thanks bro