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

optimize decompilation #58

Closed truj closed 3 years ago

truj commented 4 years ago

The decompilation process needs some optimizations.

EDIT:

EDIT:

truj commented 4 years ago

After changing the config defaults I found problems in a song. These can be boiled down to the following examples:

INSTRUMENTS
    0    PERCUSSIVE_ORGAN       PERCUSSIVE_ORGAN
END

0  c    /4 d=100%
0  d,b  /4
0  b    /4

* tempo   95
INSTRUMENTS
    0    PERCUSSIVE_ORGAN       PERCUSSIVE_ORGAN
END

0 -     /4
0  c    /4 d=100%
0  d,b  /4
0  b    /4

* tempo   95

They cause different errors. Maybe caused by the same problem, maybe not. Find the problem and fix it.

truj commented 3 years ago

Found the reason for https://github.com/truj/midica/issues/58#issuecomment-683308440. The Note-OFF tick is moved in order to be able to integrate the note into a chord. However, it has been moved to the tick of the next Note-ON of the same note. This caused an exception later because the ON tick is still in the note history but not in the ON/OFF history.

Tried to auto-correct similar issues by moving all conflicting ONs and OFFs to the same direction, without losing any of them. This avoided exceptions. However it makes the whole decompilation process much more complicated and less reliable. And the MIDI output is still not correct.

So I'll stick with the following workaround: