Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

creating note from abc notation #44

Closed
jisike opened this issue Oct 2, 2017 · 12 comments
Closed

creating note from abc notation #44

jisike opened this issue Oct 2, 2017 · 12 comments

Comments

@jisike
Copy link

jisike commented Oct 2, 2017

Are there any functions for creating a note from abc notation?

@danigb
Copy link
Collaborator

danigb commented Oct 2, 2017

Currently there's no support for abc notation. If you mean convert a note from, for example "c" to "C5", it should be easy to implement using note.build function.

What do you need this for?

@jisike
Copy link
Author

jisike commented Oct 2, 2017

I'm trying to computationally parse an abc string it into an object, manipulate it (ie change tones, pitch and etc) using tonal and convert it back into a string.

@danigb
Copy link
Collaborator

danigb commented Oct 3, 2017

I've wrote the tonal-abc-notation: http://danigb.github.io/tonal/api/module-abc-notation.html

You can install it using npm. Hope it helps.

@danigb danigb closed this as completed Oct 4, 2017
@jisike
Copy link
Author

jisike commented Oct 7, 2017

Thanks for the reply! How can I use that module in the browser?

@danigb
Copy link
Collaborator

danigb commented Oct 8, 2017

You can use a tool that can convert from node modules to browser modules. I think the easiest one is browserify: http://browserify.org/

The other option is to use a tool like budo: https://github.com/mattdesl/budo. It's easier to get started, but after you will need to use browserify or something similar.

Hope it helps.

@jisike
Copy link
Author

jisike commented Oct 8, 2017

Thanks! I have Tonal running in the browser but now I'm not able to call functions from it in the console. Any tips?

@danigb
Copy link
Collaborator

danigb commented Oct 8, 2017

If you are using the including the file from the dist/ folder, like this: <script src="tonal.min.js"></script>, you can write at the console: Tonal.midi('c4') and it should work.

But abc-notation module is not included in the bundled file. So, to use it, you need to create a file like index.js with something like:

// use the Abc module standalone
const Abc = require("tonal-abc-notation");
console.log(Abc.toAbc("C#4"));

// use it with Tonal
const Tonal = require("tonal");
console.log(Tonal.Scale.notes("Bb major").map(Abc.toAbc));

and then use browserify to create a browser compatible version (and load that file with a <script> tag inside an html file). Hope it helps.

@jisike
Copy link
Author

jisike commented Oct 8, 2017

Thanks. As I mentioned I have it bundled using browserify and running in the browser. I just asking if its possible to call functions in the console. If so how? Thanks again!

@danigb
Copy link
Collaborator

danigb commented Oct 8, 2017

Yes, I don't know if I get you 😆

You can open a console using the browser's developer tools, and write Tonal.Scale.notes("C major") and you will see the output (an array of notes). This just works.

@jisike
Copy link
Author

jisike commented Oct 9, 2017

It doesnt work for me. When I tried to call:

Tonal.Scale.notes("C major")

and I get this error:

VM2704:1 Uncaught ReferenceError: Tonal is not defined
    at <anonymous>:1:1

@danigb
Copy link
Collaborator

danigb commented Oct 9, 2017

If you use the tonal.min.js dist file, it works out of the box. If you are transpiling your own sources, you must export the tonal facade inside your code: window.Tonal = Tonal; (and window.Abc = Abc; if you want to use it from the console)

Hope it helps!

@jisike
Copy link
Author

jisike commented Oct 9, 2017

That works! Thanks for answering these general JS questions! Can I also ask how you recommend structuring the other vars and functions (that aren't in a class) to access in the same way? I tried using a closure but that didn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants