moinejf / abc2svg

project moved to https://chiselapp.com/user/moinejf/repository/abc2svg
GNU Lesser General Public License v3.0
48 stars 7 forks source link

Problems to integrate player with sf2 in other applications #85

Closed bwl21 closed 6 years ago

bwl21 commented 6 years ago

This is a followup of #83 - I move the off-topic discussion to be continued here

I managed to get the player work somehow.

  1. I had to adjust jsdir just to be '' (empty string). jsdir tries to find the path to a js folder. In Zupfnoter I have ace.js and dropbox etc. loaded from various folders, even from various servers. So the current definition of jsdir might reveal whatever directory, but not the root of the application.
  2. I defined loadjs within zupfnoter.

    Would it be possible to put these functions in a common module (or even toaudio.js). It appears to me that in needs to be defined in the global namespace.

    Of course it could also be an approach that an embedding application needs to provide this function. Is it used for anything else than loading soundfonts? I no, It could even be defined in toaudio.js.

bwl21 commented 6 years ago

@moinejf wrote in https://github.com/moinejf/abc2svg/issues/83#issuecomment-375425612

About loadjs, this function works only in a web browser context, as toaudio5, and it is used to load any kind of javascript (modules). The equivalent function for a batch context is loadRelativeToScript. I don't want to put these fonctions into the core, but you may do it.

@moinejf wrote in #83 jsdir has to be defined in the script from which all the abc2svg specific js files will be loaded.

loadjs is used for the soundfonts and the language texts, and also for the modules (actually, capo, diag, grid and psvg).

I planned to move some rarely used features, as %%MIDI, to modules in the future.

bwl21 commented 6 years ago

Ok, it would not be a problem to define jsdir in Zupfnoter. But I wonder if it is ok to define it in the global namespace. Shouldn't it be a property of ABC and initialized after or when instantiating Abc (for example in the user object)?.

I also wonder if loading of the modules is to be done differently in batch (using loadRelativeToScript) and in browser using (loadjs).

maybe you need a kind of polyfill.

I am afraid the module approach makes integration of abc2svg more complex. Up to now it is one minified js-File and the soundfonts. In an integrator also has to deal with the module files.

bwl21 commented 6 years ago

jsdir and loadjs

For the time being, I now include another file called abcsvg_poyfill.js to my application. But I consider it as workaround.

I really would prefer to pass these settings somehow to Abc, for example with the user object. By this it would

// abc2svg_polyfill.js
// this file does some settings to ensure that abc2svg player can find soundfonts and modules.
// see https://github.com/moinejf/abc2svg/issues/85
//
// these settings were made in abcdoc-1.js which is not included in Zupfnoter
// the settings (in particuler "jsdir" is also specific for Zupfnoter
//
// Todo: optimize the architecture

  var jsdir = '';

  function loadjs(fn, relay) {
    var s = document.createElement('script');
    s.src = jsdir + fn;
    s.type = 'text/javascript'
    if (relay)

storing parameters in cookies

to be honest I would prefer if persistence of parameters would be handled in the top level application (e.g. edit-1.xhtml) and not in the included libraries. Every application might have its own approach for persisting user settings.

BTW. It would also be cool if edit-1.xhtml would persist the entered abc code such that it comes back when user refreshes the screen.

moinejf commented 6 years ago

jsdir and loadjs As you may see, loadjs is very simple, and jsdir is needed to retrieve the path of the dynamically loaded scripts. You are free to implement these function/variable as you want. You may also avoid module loading by including all the modules into one of your scripts. They would work the same.

Cookies If you don't use edit.xhtml, and if you don't change the preferences, there will never be any cookies. I find better to access the cookies from the audio5 script: this permits the users to define, for example, an other path to their own soundfounds. Otherwise, if you force the audio5 parameters, the cookies are ignored. So, you can implement the persistence of these parameters in any way you want.

About persistant ABC code in the editor, I will not do it. Don't forget that this editor is just an example of what can be done with abc2svg. On the other side, the web browsers don't allow accessing the local file system. A full ABC editor would ask for either a local HTTP server or an off-line browser.

bwl21 commented 6 years ago

jsdir and loadjs

I agree, that I can implement this as I want. But the names should somehow be part of the interface of abc2svg. Now it something which needs to be provided by the calling application besides the interface documented in the core interface documentation.

If I include the modules in my compiled scipt, won't they be loaded again via loadjs?

cookies:

I do not use edit.xhtml, but I change some parameters in AbcPlay. Therefore, i get unintended cookie: sft, follow, volume.

        abcplay = new AbcPlay({
             onend: function(){#{call_on_songoff}}, // todo: activate after fix https://github.com/moinejf/abc2svg/issues/43
             onnote: function(index, on,  custom){#{call_on_note(`index`, `on`, `custom`)}}
          })
          abcplay.set_sfu("public/soundfont/Scc1t2")
          abcplay.set_sft('js')
          abcplay.set_follow(true)
          abcplay.set_vol(1.0)

path to soundfont etc. should be set by the calling application (e.g. edit.xhtml or zupfnoter). User (not the integrator) has no other way to set the coookie. And using the cooki for this is a kind of backdoor :-)

Yes the cookies are ignored, but they are still created. I will implement a cleaner in Zupfnoter to remove the same.

Persistence of ABC: Maybe it is a misunderstanding. I did not ask for a save/load. But sometimes one is playing around in edit.xhtml and by whatever reason leaves the page. The the ABC-Text is gone. As you are saving the settings etc, abc-Code could also be save in localstorage such that i reappears when reloading the page. This is what I do with Zupfnoter and it really helps. But if you consider edit.xhtml mainly as demo and not for production it is not that important. I asked for this since when I use edit.xhtml to try somehting in abc2svg, i have to reload the page when I do changes to abc2svg. And then I have to paste the testcase again.

moinejf commented 6 years ago

jsdir and loadjs As you may know, the modules handle rarely used and non standard ABC features. When the modules are included with the abc2svg core, they are not loaded anymore. I will write some documentation about them.

cookies Well, you are right, the cookies must not be set from the audio5 script. I will move the settings to the editor and use localStorage instead.

Persistence of ABC I did not know about session and local storage I will have a look.

bwl21 commented 6 years ago

I made a prerelease of my app yesterday. So basically, we could close this. I am still not convinced that it is wise to expect loadjs in the global namespace. It needs to be provided by the integrator. Therefore it is defined in abcemb and in abcdoc. From architectural standpoint IMHO it would be better to pass the function to Abc resp. AbcPlay either by configuration or by a setter.

At least it should be documented in https://github.com/moinejf/abc2svg/blob/master/doc/interface-1.xhtml

bwl21 commented 6 years ago

i close this, as it is now documented in https://github.com/moinejf/abc2svg/wiki/Interface-1