abcjs icon indicating copy to clipboard operation
abcjs copied to clipboard

Imperitive style coding possible?

Open abalter opened this issue 3 years ago • 1 comments

Abcjs is awesome. Note that I'm a sponsor :) I made this app for my personal use. My issue is probably because I'm not a very good javascript programmer.

Right now, every time I want to update the player with new ABC text I have to call the function updateTune which creates an entire new ABCJS.Editor and tell it the text area and player div all over again.

I would like to be able to use abcjs in a more imperative way such as:

let abc_text_element = $('#abc_txt_element');
let rendered_music_player_element = $('#rendered_music_element');

let abcjs_tool = new ABCJSTool();

let abc_text = abc_text_element.text();
let abc_music_png = abcjs_tool.render(abc = abc_text, output="png"); // then put image in <img> tag.

/* or */

let abc_music_player = abcjs_tool(player);
abc_music_player.render_in = rendered_music_player_element;
abc_music_player.render(abc_text); // ABC notation in abc_text rendered to player

abc_text = "....some ABC notation...";
abc_music_player.render(abc_text); // ABC notation in abc_text rendered to player

abc_text = "....some new ABC notation...";
abc_music_player.render(abc_text); // ABC notation in abc_text rendered to player

// paste new text into the text area
abc_text = abc_text_element.text();
abc_music_player.render(abc_text); // ABC notation in abc_text rendered to player

// add a new place to render a player
let new_render_place = window.append('<div>');
abc_music_player.render_in = new_render_place;
abc_muci_player.render(abc_text)

abalter avatar Sep 13 '22 20:09 abalter

I'm not positive I know exactly what you are doing, but I think you don't need to call your updateTune function at all. If you are just changing the ABC text you can change it and the editor should pick up the changes, like abc_text_element.value = "x:1\netc..." Do you have an online example of your app? That would be easier for me to see what you are doing.

paulrosen avatar Sep 18 '22 15:09 paulrosen

Is there still a question here? I'm happy to reopen if so.

paulrosen avatar Oct 22 '22 15:10 paulrosen