SharedUse-Abjad-in-CoCalc.ipynbOpen in CoCalc
Authors: Samuel Lelièvre, Jeffrey Trevino
Views : 3
Description: Composing music with Abjad on CoCalc

Using Abjad and Lilypond in CoCalc

In a CoCalc terminal, run

pip3 install Abjad
pip3 install abjad-ext-ipython

Then, as this worksheet shows, displaying music works!

What does not work so far is playing music. This is because abjad.play relies on timidity. Feature request for abjad.play: allow to specify a player, such as a javascript player.

For example, by allowing abjad.play(staff, player='midijs') or similar.

In [1]:
import abjad
In [6]:
%load_ext abjadext.ipython
In [7]:
note = abjad.Note()
In [8]:
note
Note("c'4")
In [9]:
abjad.show(note)
In [10]:
from random import randint pitch_numbers = [randint(-7,24) for x in range(100)] pitch_numbers[:10]
[8, 10, 11, 22, 3, 19, 22, -4, 20, -7]
In [11]:
notes = [abjad.Note(x,(1,32)) for x in pitch_numbers]
In [12]:
staff = abjad.Staff(notes)
In [13]:
abjad.show(staff)
In [14]:
abjad.play(staff)
--------------------------------------------------------------------------- CalledProcessError Traceback (most recent call last) <ipython-input-14-86a9b915fe20> in <module>() ----> 1 abjad.play(staff) ~/.local/lib/python3.6/site-packages/abjadext/ipython/Play.py in __call__(self, argument) 24 if not hasattr(argument, '__illustrate__'): 25 raise TypeError('Cannot play {!r}'.format(type(argument))) ---> 26 has_vorbis = self._check_for_vorbis() 27 with tempfile.TemporaryDirectory() as temporary_directory: 28 temporary_directory = pathlib.Path(temporary_directory) ~/.local/lib/python3.6/site-packages/abjadext/ipython/Play.py in _check_for_vorbis(self) 48 def _check_for_vorbis(self): 49 has_vorbis = False ---> 50 output = subprocess.check_output('timidity --help', shell=True) 51 output = output.decode('utf-8') 52 for line in output.splitlines(): /usr/lib/python3.6/subprocess.py in check_output(timeout, *popenargs, **kwargs) 334 335 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, --> 336 **kwargs).stdout 337 338 /usr/lib/python3.6/subprocess.py in run(input, timeout, check, *popenargs, **kwargs) 416 if check and retcode: 417 raise CalledProcessError(retcode, process.args, --> 418 output=stdout, stderr=stderr) 419 return CompletedProcess(process.args, retcode, stdout, stderr) 420 CalledProcessError: Command 'timidity --help' returned non-zero exit status 127.
In [ ]: