Skip to content

Support for conditional directives #983

@martijnversluis

Description

@martijnversluis

Conditional directives

All directives can be equipped with a selector by appending a selector name to the name of the directive, separated by a dash (hyphen) -. If the selector fails, the directive is skipped.

For example:

{define-ukulele Dm base-fret 1 frets 2 2 1 0}
{define-guitar  Dm base-fret 1 frets x 0 3 2 3 1}

This will define the appropriate Dm chord for either ukulele or guitar.

Selection can be reversed by appending a ! to the selector.

How selectors are defined depends on the ChordPro processing tool. The ChordPro program uses the config values for instrument.type and user.name.

See https://www.chordpro.org/chordpro/chordpro-directives/#conditional-directives

  • parse selector on Tag
  • store selector on Line and Paragraph
  • allow testing the condition
  • allow ! for reversing the selector
  • render sections conditionally based on selector
  • set metadata conditionally based on selector
  • return chord definitions conditionally

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions