Re: audible metronome in MIDI file?

2022-04-27 Thread Jean Abou Samra

Le 28/04/2022 à 04:31, Kieren MacMillan a écrit :
I was thinking the very same thing — seems like a custom performer (or 
engraver?) would be amazing for this. I hope Someone™ likes the idea 
enough to code it up!




Well, I tried that yesterday: it has become possible to write Scheme
performers with change from David K. in the 2.23 series. I arrived at
the following, but ultimately decided not to post it because there
is a big bad bug: if there is  no note or rest or skip or some sort
of event at a point of time, a tick can't get added there. That makes
it practically unusable. A pity that Global_context::add_moment_to_process
is not Scheme-accessible ...


Regards,
Jean



\version "2.23.9"

#(define (Metronome_performer context)
   (make-performer
    ((process-music performer)
 ;; TODO: check is baseMoment is always accurate
 (let ((reg (ly:context-property context 'baseMoment)))
   (when reg
 (let* ((mp (ly:context-property context 'measurePosition))
    (strength
 (cond
  ((equal? mp ZERO-MOMENT)
   'main)
  ((integer? (ly:moment-main (ly:moment-div mp reg)))
   'secondary)
  (else
   #f
   (when strength
 (let* ((source (ly:context-event-source context))
    (cls (ly:make-event-class 'note-event))
    (type (case strength
    ((main) 'hiwoodblock)
    ((secondary) 'lowoodblock)))
    (props `((drum-type . ,type)
 (length . ,reg)))
    (ev (ly:make-stream-event cls props)))
   (ly:broadcast source ev)

\midi {
  \context {
    \name MetronomeTrack
    \type Performer_group
    %% This is veery ugly, but currently it is not possible to
    %% create audio items from Scheme performers, so ...
    \remove Drum_note_performer
    \consists #Metronome_performer
    \consists Drum_note_performer
    midiInstrument = "drums"
  }
  \inherit-acceptability MetronomeTrack DrumVoice
}

\layout {
  \context {
    \Score
    \accepts MetronomeTrack
  }
  \context {
    \Devnull
    \name MetronomeTrack
  }
}

%% Awful, but how to do better?? Of course, ideally the Metronome_performer
%% would be on Score level and create audio items itself, but for the time
%% being we have to use Drum_note_performer, which would duplicate drum 
notes

%% from all the score if it were put on Score level ...

#(set! toplevel-music-functions
   (cons (lambda (m)
   #{
 <<
   #m
   \new MetronomeTrack { #(skip-of-length m) }
 >>
   #})
 toplevel-music-functions))

\score {
  \midi { }
  \layout { }
  \relative c' {
    c'4( d8 e f g a b) c4( b8 a g f e d) c4-. c'-. c,2-^
  }
}




Re: audible metronome in MIDI file?

2022-04-27 Thread Kieren MacMillan
Hi Gilles,

> In order to be universally useful, shouldn't this functionality be able
> to pick up the time signatures and create the appropriate sequence
> of "ticks" (strong and weak), roughly similarly to what happens with beams?

I was thinking the very same thing — seems like a custom performer (or 
engraver?) would be amazing for this. I hope Someone™ likes the idea enough to 
code it up!

Cheers,
Kieren.


Re: audible metronome in MIDI file?

2022-04-27 Thread Jimmy Wilkinson
Thanks. That's what I was looking for. I hacked on it a bit.






Re: audible metronome in MIDI file?

2022-04-27 Thread Gilles Sadowski
Hi.

> [...]
>
> The typical solution for that is an additional drum staff with high- and low 
> woodblocks in parallel to the actual music as shown in a snippet of the 
> snippet repository:
> https://lsr.di.unimi.it/LSR/Item?id=876
>

In order to be universally useful, shouldn't this functionality be able
to pick up the time signatures and create the appropriate sequence
of "ticks" (strong and weak), roughly similarly to what happens with
beams?

Regards,
Gilles

> [...]



Re: audible metronome in MIDI file?

2022-04-27 Thread Hans Aikema

> On 27 Apr 2022, at 09:06, Jimmy Wilkinson  wrote:
> 
> I’d like to hear a metronome in the MIDI file generated by Lilypond. The best 
> thing I can think of is to add a new voice that plays some high short note at 
> the beginning of each beat. I’m hoping that there’s a better (easier?) way 
> that I haven’t found.  It’d be nice if I could just ask Lilypond to do that 
> and have it affect only the MIDI file and not show in the printed score.
> 
> thanks


Jimmy,

The typical solution for that is an additional drum staff with high- and low 
woodblocks in parallel to the actual music as shown in a snippet of the snippet 
repository:
https://lsr.di.unimi.it/LSR/Item?id=876 



Its source code (https://lsr.di.unimi.it/LSR/Snippet?id=876 
) also shows (in the comments) how 
to make that drum staff only appear in the MIDI and not in the printed sheet by 
using a tag for the ‘midiOnly’ drum staff

In my use I typically work with transferring final arrangements into lilypond 
code so that I know the bar-counts, so I don’t use the makeUnfold function 
defined in that snippet but just use \repeat \unfold as referenced in the 
comments.

Kind regards,
Hans