midi output

63 views
Skip to first unread message

Iain Harvie

unread,
May 11, 2023, 6:12:03 PM5/11/23
to abjad-user
I am a new user of abjad. so apologies if I am missing something obvious. The documentation for v3.17 details how to specify a midi player in an abajad.cfg file, but I cannot see how to output a midi file. Previous examples and documentation use abjad.play() but v3.17 returns <AttributeError: module 'abjad' has no attribute 'play'>

I can't see anything on https://github.com/Abjad/abjad/releases that covers this change.

Trevor Bača

unread,
May 12, 2023, 2:10:03 PM5/12/23
to abjad...@googlegroups.com
I've removed abjad.play().

Just include a \midi block in any abjad.LilyPondFile instead.

On Thu, May 11, 2023 at 6:12 PM Iain Harvie <del...@gmail.com> wrote:
I am a new user of abjad. so apologies if I am missing something obvious. The documentation for v3.17 details how to specify a midi player in an abajad.cfg file, but I cannot see how to output a midi file. Previous examples and documentation use abjad.play() but v3.17 returns <AttributeError: module 'abjad' has no attribute 'play'>

I can't see anything on https://github.com/Abjad/abjad/releases that covers this change.

--
You received this message because you are subscribed to the Google Groups "abjad-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to abjad-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/abjad-user/dda9abd5-6b92-43cb-9444-aa18da5b91f9n%40googlegroups.com.


--

Iain Harvie

unread,
May 15, 2023, 11:42:08 AM5/15/23
to abjad-user
Thank you Trevor. That makes sense. 
I have the following code:
----
import abjad

voice = abjad.Voice("c'4 d'4 e'4 f'4", name="Voice")
midi = abjad.Block("midi")

score = abjad.Score([voice], name="Score")

midi_score = abjad.LilyPondFile([score, midi])

abjad.show(midi_score)

----
Which seems correct,  adds the midi block and compiles without errors. But abjad.Score creates the score as a context and abjad.LilyPondFile concatenates the midi block to that context:

\version "2.24.0"

\language "english"

\context Score = "Score"
<<

    \context Voice = "Voice"
    {
        c'4
        d'4
        e'4
        f'4

    }

>>
\midi {}

Lilypond seems to require the \midi block to be nested in a \score block and no midi output is produced. I am unsure how to achieve this.

iain

Trevor Bača

unread,
May 15, 2023, 3:30:27 PM5/15/23
to abjad...@googlegroups.com
Hi Iain,

Use abjad.Block to create a \score block, just the same as for a \midi block:

voice = abjad.Voice("c'4 d'4 e'4 f'4", name="Voice")
staff = abjad.Staff([voice], name="Staff")
score = abjad.Score([staff], name="Score")
midi_block = abjad.Block("midi")
score_block = abjad.Block("score", [score, midi_block])
lilypond_file = abjad.LilyPondFile([score_block])
string = abjad.lilypond(lilypond_file)

print(string)
\version "2.25.3"
\language "english"
\score
{
    \context Score = "Score"
    <<
        \context Staff = "Staff"
        {

            \context Voice = "Voice"
            {
                c'4
                d'4
                e'4
                f'4
            }
        }
    >>
    \midi {}
}

HTH,

Trevor.

Iain Harvie

unread,
May 15, 2023, 4:25:04 PM5/15/23
to abjad-user
Thanks again Trevor. 
It might be worth adding (if only for the sake of any subsequent new users reading this) that when using an explicit \score block that Lilypond only compiles a pdf if there is a \layout block within the \score block. The following code outputs a midi file and a pdf file.

voice = abjad.Voice("c'4 d'4 e'4 f'4", name="Voice")
staff = abjad.Staff([voice], name="Staff")
score = abjad.Score([staff], name="Score")
midi_block = abjad.Block("midi")
layout_block = abjad.Block("layout")
score_block = abjad.Block("score", [score, layout_block, midi_block])

lilypond_file = abjad.LilyPondFile([score_block])
abjad.show(lilypond_file)

iain
Reply all
Reply to author
Forward
0 new messages