[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Add Staff.midiCC context property, refactor handling of MIDI control cha

From: ht . lilypond . development
Subject: Add Staff.midiCC context property, refactor handling of MIDI control changes (issue 284280043 by address@hidden)
Date: Sat, 16 Jan 2016 18:08:08 +0000

Reviewers: ,


This patch introduces an interface for adjusting the values of all MIDI
controllers responding to Control Change events from within LilyPond
using context properties.  Instead of adding a new context property for
every controller, however, this change adds a generic Staff.midiCC
property, which accepts a list of (control number, value) pairs, where
control number and the value are integers between 0 and 127 (inclusive).
Setting the context property will generate the corresponding "raw"
change events in the MIDI output.

In hindsight, the generic context property would have provided (from a
purely technical standpoint) an interface sufficient for making changes
all of the MIDI controls for whose adjustment I have previously added
support using controller-specific context properties (Staff.midiBalance,
Staff.midiExpression, Staff.midiPanPosition, Staff.midiReverbLevel and
Staff.midiChorusLevel).  I realize that the introduction of another
property whose value syntax differs from that of the existing ones, but
whose behavior still overlaps with them, will reduce the overall
consistency of the design, but in my opinion there are the following
arguments for making this change:

* The main single benefit of the new context property is that it enables
  making changes to the values of any MIDI controllers adjustable using
  MIDI control change events from within LilyPond input files without
  polluting the LilyPond context property namespace.  (Even after this
  change, there still remain MIDI controls whose values cannot be
  from within LilyPond input, such as Channel Pressure or Pitch Wheel -
  however, the current patch concerns only enhancing support for MIDI CC

* There are no changes added which would _require_ setting the context
  property in any existing LilyPond files: just as with the other MIDI
  context properties, users need to concern themselves with the new
  property only if they need it.

* This patch simplifies the implementation of handling the existing MIDI
  context properties by reducing their implementation to use the same
  structures for outputting MIDI control changes.  Adding support for
  new controller-specific context properties should be as easy (or even
  easier) as before because the definitions of the controller-specific
  context properties are now located in a single file
  (lily/ instead of being scattered over several
  Audio_item and Midi_item subclasses.

In my opinion, the alternative to adding a generic context property for
generating MIDI control changes - that is, adding new context properties
separately each controller - would only lead to a burden of having to
a lot of new technical documentation (which would have more to do with
MIDI standard, not LilyPond) because:

- the names of MIDI controllers do not appear to be very strictly
  so the context properties could not be named without documenting also
  their associated MIDI controller numbers (unless the numbers were
  in the property names, of course - however, this option would probably
  make the names so generic that having separate context properties for
  every controller would bring little benefit over the Staff.midiCC

- on the other hand, due to the genericity of many of the names of
  controllers (<>), and
  freedom given by the standard as regards their function, choosing too
  specific names for the context properties would likely result in the
  not matching the actual function of the corresponding controllers well
  across different MIDI devices; and

- each context property would need a decision on how to represent its
  in LilyPond input.  However, any value representation scheme that does
  use "raw" MIDI values (integers between 0 and 127), could make it
  for advanced MIDI users who wish to use particular integer values of
  own choosing for MIDI output: with custom schemes for specifying
  for the context properties, having a particular integer value
outputted in
  MIDI would not be possible without precise knowledge about how
  handles the values of the context properties, in order to do reverse
  calculations.  (I do not claim that custom value types would
  be bad for all controllers: for example, a context property which
  Boolean values could be a natural choice for controller types that
  have an "on" or "off" setting.)

As this patch will not remove any existing functionality, but only
it, I see no reason to remove support for the controller-specific
properties, even though the behavior of the new context property
with that of the existing ones.  The controller-specific properties
could be
seen just as a convenience interface for adjusting the values of
controllers, and even new controller-specific properties could be
later if necessary, whereas the generic Staff.midiCC property is
provided to
allow making direct adjustments even to more rarely used (or MIDI device
specific) controllers if necessary.

A few small additional notes about the design of the changes in the

* The current implementation of the Staff.midiCC context property always
  requires a list as the context property value.  It would be possible
  add support for accepting single (control number, value) pairs as
  themselves, but I think this would require extending scm/c++.scm and
  scm/lily.scm with an "integer-pair-or-integer-pair-list" predicate,
  to me feels like too specific a predicate to warrant being added to
  public definitions.  (I guess one cannot use lambda expressions as
  context property predicates in scm/define-context-properties.scm?)

* When updating the Changes document, I did not put the description of
  new context property to the top of the file, but added it after the
  description of the Staff.midiExpression context property - I think it
  more logical to describe these context properties together.

Add Staff.midiCC context property, refactor handling of MIDI control

Setting the Staff.midiCC context property to a list of (control number,
control value) pairs, where every control number and control value must
be an integer between the inclusive range from 0 to 127, will send the
corresponding raw control changes to the MIDI output on the MIDI channel
associated with the current context.  For example,
\set Staff.midiCC = #'((7 . 100)) will set the MIDI volume control (#7)
to 100.

Most of the logic for handling MIDI control value initialization from
context properties (in Staff_performer::new_audio_staff),
changes (in
Midi_control_function_performer::announce_function_value_change), and
value conversion for output (in
Midi_control_function_value_change::to_string), was moved into the new
Midi_control_change_announcer class.  All MIDI control changes are now
encoded using {Audio,Midi}_control_change items.  This change makes the
old {Audio,Midi}_control_function_value_change classes obsolete.

Please review this at

Affected files (+374, -185 lines):
  M Documentation/changes.tely
  M Documentation/notation/input.itely
  M lily/
  M lily/include/audio-item.hh
  M lily/include/lily-proto.hh
  A lily/include/midi-cc-announcer.hh
  M lily/include/midi-item.hh
  A lily/
  M lily/
  M lily/
  M lily/
  M scm/c++.scm
  M scm/define-context-properties.scm
  M scm/lily.scm

reply via email to

[Prev in Thread] Current Thread [Next in Thread]