truj / midica

A Music programming language. Translates source code into MIDI. Includes a player. Supports MIDI-Karaoke. Includes a MIDI analyzer.
https://www.midica.org/
Mozilla Public License 2.0
111 stars 13 forks source link

Add bar line check #74

Closed truj closed 1 year ago

truj commented 2 years ago

In compact syntax (only there), add a bar line that can be used for automatic checks. When a bar symbol is set, the parser should check if the current ticks of the according channel match the border of a measure. That is done the following way:

  1. Find the last global command setting a time
  2. Calculate how many ticks this is ago
  3. Calculate how many ticks must be in one measure
  4. Divide (2) by (3) and get the rest (modulo division)

If the Rest is 0, show an error (and maybe also a stack trace)

Problem: Some rare combinations of (nested?) tuplets and/or dotted notes may result in rounded note lengths. And a Channel may have more of these cases producing small errors that sum up to a larger error.

Solution: Allow a tolerance value (in ticks) as a parameter to the measure symbol. (Default is 0)

Example without parameters:

* time 4/4
0:   c:4 c c c | d d d:8 d d d | c:4 d e | c c c c

The one after the note e should cause an error.

Example with parameters:

* time 4/4
{ t
    { t
        0:  c:4 c c
    }
    0:  c:2 c
}
0:   c:4 d e f  |3  c d e f

In this case |3 would do a check allowing a tolerance of 3 ticks. Or maybe |3| would be better (easier to read)?

truj commented 1 year ago

Documentation: http://www.midica.org/tutorial-2.html#barlines