CoderLine / alphaTab

alphaTab is a cross platform music notation and guitar tablature rendering library.
http://www.alphatab.net
Mozilla Public License 2.0
1.27k stars 202 forks source link

Recognize track type #358

Closed yaras6 closed 4 years ago

yaras6 commented 4 years ago

Question

Is there a way to recognize is a track a guitar/keyboard/bass/percussion/other?

image

Your environment

Danielku15 commented 4 years ago

You can fully rely on the midi information to identify whether a track is a percussion tab and which instrument it is.

From a playback perspective the midi channel value 9 is considered the percussion channel. A small detail might be that the channels are 0 indexed, meaning that channel value 9 is the 10th channel and by this a percussion channel.

The program defines the midi instrument. See lists like on Wikipedia for details to map them to instrument groups: https://en.wikipedia.org/wiki/General_MIDI#Program_change_events

The staff.isPercussion is more for the visual aspect of rendering drum tabs while the playback information defines how it sounds on playback. Of course usually isPercussion == true and playbackInformation.program == 9 are the same from the input files.

You can build easily something like:

function getTrackType(track) {
    const pi = track.playbackInfo;
    if(pi.primaryChannel === 9) {
        return 'Percussion';
    } else if(pi.program <= 7) {
        return 'Piano';
    } else if(pi.program <= 15) {
        return 'Chromatic Percussion';
    } else if(pi.program <= 23) {
        return 'Organ';
    } else if(pi.program <= 31) {
        return 'Guitar';
    } else if(pi.program <= 39) {
        return 'Bass';
    } else if(pi.program <= 47) {
        return 'Strings';
    } else if(pi.program <= 55) {
        return 'Ensemble';
    } else if(pi.program <= 63) {
        return 'Brass';
    } else if(pi.program <= 71) {
        return 'Reed';
    } else if(pi.program <= 79) {
        return 'Pipe';
    } else if(pi.program <= 87) {
        return 'Synth Lead';
    } else if(pi.program <= 95) {
        return 'Synth Pad';
    } else if(pi.program <= 103) {
        return 'Synth Effects';
    } else if(pi.program <= 111) {
        return 'Ethnic';
    } else if(pi.program <= 119) {
        return 'Percussive';
    } else if(pi.program <= 127) {
        return 'Sound effects';
    }
    return 'Unknown';
}
yaras6 commented 4 years ago

Thanks, this sample works perfect

MrDrone-ru commented 2 years ago

The question arose, how to map MIDI program value to a standart General MIDI instrument name. A good option is: github.com/jazz-soft/JZZ-midi-GM