2

I am a beginner having difficulties using Julia's PyCall to interface with the MIT Python music module music21.

According to Music21’s website, in order to display a short melody in musical notation one would type this in Python:

converter.parse("tinynotation: 3/4 c4 d8 f g16 a g f#").show()

Here is what I did to try and execute this code in Julia:

I first initialized music21, which seemed to work:

@pyimport music21
music21: Certain music21 functions might need these optional packages: matplotlib, scipy; if you run into errors, install them by following the instructions at http://mit.edu/music21/doc/installing/installAdditional.html

Then I tried to recreate the above Python example in Julia by typing:

converter.parse("tinynotation: 3/4 c4 d8 f g16 a g f#").show()

I received this error:
ERROR: UndefVarError: converter not defined
Stacktrace:
 [1] eval(::Module, ::Any) at ./boot.jl:235

UPDATE 1 According to rickhg12hs's suggestion, I attempted music21.converter.parse("tinynotation: 3/4 c4 d8 f g16 a g f#").show().

Now I am getting this error message on 'Parse': ERROR: type PyObject has no field parse Stacktrace: 1 eval(::Module, ::Any) at ./boot.jl:235

It seems like an improvement as it is now crashing a little later in the code chain, at 'Parse' instead of 'Converter'.

UPDATE 2 - FIXED This issue has to do with dot overloading. Based on this link, I tried modifying my code to look like this:

music21.converter[:parse]("tinynotation: 3/4 c4 d8 f g16 a g f#")[:show]()

but now I get this error

FSPathMakeRef(/Applications/MuseScore 2.app/Contents/MacOS/mscore) failed with error -43.

I discovered that the last thing I had to do was to download MuseScore and now the problem is fixed!

See @crstnbr's answer for more context on the ugliness of this solution and imminent fixes.

Many thanks! Nakul

Nakul Tiruviluamala
  • 523
  • 1
  • 3
  • 15
  • I've never used this Python package (and you would cringe at my guitar playing), but I'm wondering what happens if you try `music21.converter.parse("tinynotation: 3/4 c4 d8 f g16 a g f#").show()`. – rickhg12hs Sep 06 '18 at 04:55
  • This is my first time using PyCall. Your suggestion might have improved the scenario a little bit. Now I am getting this error message on 'Parse': ERROR: type PyObject has no field parse Stacktrace: [1] eval(::Module, ::Any) at ./boot.jl:235 – Nakul Tiruviluamala Sep 06 '18 at 05:18
  • Would you edit your question to include this new information? It helps everyone who may look at this issue later. – rickhg12hs Sep 06 '18 at 05:22
  • Thanks for the suggestion. I just did. – Nakul Tiruviluamala Sep 06 '18 at 05:30
  • @crstnbr shows the (temporarily ugly) way. – rickhg12hs Sep 06 '18 at 05:37

1 Answers1

3

I don't have the package installed (I'll test it in a second) but the following should work:

@pyimport music21 as m
m.converter[:parse]("tinynotation: 3/4 c4 d8 f g16 a g f#")[:show]() 

Note that the arguably ugly (but systematic) [:fieldname] access will go away sometime soon in Julia 1.0 after my Pull request here gets merged. The reason for this syntax is that Julia didn't allow to override the . access functionality. This, fortunately, changed in Julia 1.0.

carstenbauer
  • 9,817
  • 1
  • 27
  • 40
  • I only installed `music21`, but this works for me `music21.converter[:parse]("tinynotation: 3/4 c4 d8 f g16 a g f#")[:show]("text")` – rickhg12hs Sep 06 '18 at 05:39
  • Thank you very much! I just independently arrived at the code solution, but your added context is very useful and interesting. I'm excited to not have to include those [:]'s once your pull request gets merged. – Nakul Tiruviluamala Sep 06 '18 at 05:40
  • Ok, guess I was to slow in installing the package :) – carstenbauer Sep 06 '18 at 05:41
  • Hey @crstnbr , Do you know if it's possible for me to implement your pull request without recompiling Julia? If not, is there a resource pointing to a straightforward way of recompiling Julia with your contribution (I am new with that fort of stuff). The more I am working with PyCall, it seems like your contribution is a HUGE timesaver. – Nakul Tiruviluamala Sep 06 '18 at 21:20
  • You don't need to recompile Julia as this is only a PyCall issue, which is an external package. You could dowload my fork of the package and use the PR's branch to try it out. However, I think you really shouldn't do that, but instead wait for the PR to get merged, as the implementation isn't completed yet and might contain bugs. – carstenbauer Sep 07 '18 at 07:51
  • I'll work on the PR on the weekend, so maybe we can already merge it next week. It will be up to Steven (the package owner). – carstenbauer Sep 07 '18 at 07:52
  • I appreciate it @crsnbr. I still need to upgrade to Julia 1.0 (I'm still using 0.6) before I can experience the enhanced . access functionality anyway. I'll stay tuned! – Nakul Tiruviluamala Sep 08 '18 at 05:06