Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize track type #358

Closed
yaras6 opened this issue May 2, 2020 · 3 comments
Closed

Recognize track type #358

yaras6 opened this issue May 2, 2020 · 3 comments
Assignees
Milestone

Comments

@yaras6
Copy link

yaras6 commented May 2, 2020

Question

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

image

Your environment

@Danielku15
Copy link
Member

Danielku15 commented May 2, 2020

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';
}

@Danielku15 Danielku15 self-assigned this May 2, 2020
@Danielku15 Danielku15 added this to the 1.0.0 milestone May 2, 2020
@yaras6
Copy link
Author

yaras6 commented May 3, 2020

Thanks, this sample works perfect

@MrDrone-ru
Copy link

MrDrone-ru commented Oct 21, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants