![]() |
MIPI - Physical Interface for MIDI Files
|
Standalone Class for processing midi files and saving/loading mipi files. Contains various getters to store and provide data about midi/mipi files. More...
#include <midi_processor.h>

Public Member Functions | |
| MidiProcessor () | |
| Constructor that allocates internals. | |
| ~MidiProcessor () | |
| Destructor. | |
| int | processMidiFile (std::string midi_file_path, std::string json_file_name) |
| processes a midi file by saving all instruments (and their channels) to a set of vectors | |
| std::vector< int > | get_channels () |
| gets all channels | |
| std::vector< int > | get_instruments () |
| gets all instruments | |
| std::vector< std::string > | get_instrument_names () |
| gets all instrument names and their channels | |
| std::vector< std::vector< int > > | get_channel_notes () |
| gets all notes | |
| std::vector< std::vector< double > > | get_channel_note_timings () |
| gets all note timings | |
| std::vector< std::vector< double > > | get_channel_note_durations () |
| gets all note durations | |
| double | get_song_duration () |
| gets the song duration | |
| std::vector< std::vector< int > > | get_assigned_keys () |
| gets all assigned keys | |
| std::vector< std::vector< int > > | get_keyboard_values () |
| get keyboard values | |
| std::vector< std::vector< int > > | get_keyboard_indexs () |
| get keyboard indexs | |
| bool | load_json_file (std::string json_file_path) |
| load JSON file | |
Private Member Functions | |
| bool | open_file (std::string midi_file_path) |
| opens a selected midi file | |
| bool | process_instruments () |
| processes and stores all instruments/channels | |
| bool | process_channel_notes (int channel) |
| processes and stores all notes that correspond to a specific channel | |
| bool | process_channel_notes_with_timings () |
| processes and stores all notes and their timings and remove dud channels | |
| bool | filter_chords () |
| filters chords down to only the root note | |
| bool | filter_trills () |
| filters trills and staggered chords down to only the first note | |
| bool | filter_overlapping_notes () |
| filters overlapping notes down to only the first note | |
| bool | process_song_duration () |
| process song duration | |
| bool | assign_keys () |
| key assignment function | |
| bool | trim_note_durations () |
| note duration trimming function | |
| bool | save_midi_data (std::string file_name) |
| stores all data for current midi file in a storage file | |
| bool | debug_print_data () |
| prints all data to the console | |
Private Attributes | |
| MidiFile | midi |
| MidiFile library. | |
| const char * | homeDir = getenv("HOME") |
| home directory | |
| double | min_note_duration_gap = 50 |
| minimum note duration | |
| double | min_note_gap = 0.08 |
| minimum note gap | |
| std::vector< int > | channels |
| current list of channels | |
| std::vector< int > | instruments |
| current list of instruments | |
| std::vector< std::vector< int > > | notes |
| current list of notes | |
| std::vector< std::vector< double > > | note_timeStamps |
| current list of note_timeStamps | |
| std::vector< std::vector< double > > | note_durations |
| current list of note_durations | |
| double | fileDuration |
| current song duration | |
| std::vector< std::vector< int > > | assigned_keys |
| current list of assigned keys for each channel | |
| std::vector< std::vector< int > > | keyboard_values |
| current list of keyboard values for each channel | |
| std::vector< std::vector< int > > | keyboard_indexs |
| current list of keyboard indexs for each channel | |
Standalone Class for processing midi files and saving/loading mipi files. Contains various getters to store and provide data about midi/mipi files.
This class contains the following accesible data:
There are 3 filters that are applied to the data before it is saved to the mipi file. These are applied in the following order:
Overlapping Notes: Notes that are completely overlap with each other the first note played is kept
| MidiProcessor::MidiProcessor | ( | ) |
Constructor that allocates internals.
Standalone Class for processing midi files and saving/loading mipi files. Contains various getters to store and provide data about midi/mipi files.
This class contains the following accesible data:
There are 3 filters that are applied to the data before it is saved to the mipi file. These are:
Overlapping Notes: Notes that are completely overlap with each other the first note played is kept
Constructor that allocates internals
< current list of channels
< current list of instruments
< current list of notes
< current list of note_timeStamps
< current list of note_durations
< current song duration
< current list of assigned keys for each channel
< current list of keyboard values for each channel
< current list of keyboard indexs for each channel
| MidiProcessor::~MidiProcessor | ( | ) |
Destructor.
|
private |
key assignment function
This function is called by the process_midi_file method. On a per channel basis, it finds the average note in a channel, shifts the keyboard values to put the average as close to the middle C as possible, then assigns each note a keyboard value of a matching pitch. If a note is outside the bounds of the keyboard values it shifts it up or down octaves until it is within the bounds.

|
private |
prints all data to the console
This function is called wherever the user wants to test the data. It prints all stored the data to the console.

|
private |
filters chords down to only the root note
This function is called by the process_midi_file method. It removes overlapping timestamps and keeps either the highest or the lowest note on that time stamp depending on the instrument type (e.g. piano = high note, guitar = low note). The affected vectors are the "notes", "note_timeStamps", and "note_durations" vectors.

|
private |
filters overlapping notes down to only the first note
This function is called by the process_midi_file method. It removes notes that are played entirely within the duration of another note. The affected vectors are the "notes", "note_timeStamps", and "note_durations" vectors.

|
private |
filters trills and staggered chords down to only the first note
This function is called by the process_midi_file method. It removes trills and staggered chords and keeps either the first note played. The affected vectors are the "notes", "note_timeStamps", and "note_durations" vectors.

| std::vector< std::vector< int > > MidiProcessor::get_assigned_keys | ( | ) |
gets all assigned keys
This function returns a vector of vectors ints. Each vector contains assigned keys for 1 channel, which correspond to a note on the keyboard values vector.
This function returns a vector of vectors ints. Each vector contains assigned keys for 1 channel, which correspond to a note on the keyboard values vector.
| std::vector< std::vector< double > > MidiProcessor::get_channel_note_durations | ( | ) |
gets all note durations
This function returns a vector of vectors of doubles. Each vector contains note durations for 1 channel.
| std::vector< std::vector< double > > MidiProcessor::get_channel_note_timings | ( | ) |
gets all note timings
This function returns a vector of vectors of doubles. Each vector contains note time stamps for 1 channel.
| std::vector< std::vector< int > > MidiProcessor::get_channel_notes | ( | ) |
gets all notes
This function returns a vector of vectors of ints. Each vector contains notes for 1 channel as it is written in the midi file.
| std::vector< int > MidiProcessor::get_channels | ( | ) |
gets all channels
This function returns a vector of integers. Each integer is a channel number

| std::vector< std::string > MidiProcessor::get_instrument_names | ( | ) |
gets all instrument names and their channels
This function returns a vector of strings. Each string is the name of an instrument and its channel number


| std::vector< int > MidiProcessor::get_instruments | ( | ) |
gets all instruments
This function returns a vector of integers. Each integer is an instrument number
| std::vector< std::vector< int > > MidiProcessor::get_keyboard_indexs | ( | ) |
get keyboard indexs
gets all keyboard indexs
This function returns a vector of vectors of ints. Each vector contains the indexs for the notes of the assigned keys as they appear in the keyboard values vector. The indexs of these keys match the corresponding indexs for the key position vector.
This function returns a vector of vectors of ints. Each vector contains the indexs for the notes of the assigned keys as they appear in the keyboard values vector. The indexs of these keys match the corresponding indexs for the key position vector.
| std::vector< std::vector< int > > MidiProcessor::get_keyboard_values | ( | ) |
get keyboard values
gets all keyboard values
This function returns a vector of vectors of ints. Each vector contains the 37 assigned keyboard values for 1 channel. The indexs of these keys match the corresponding indexs for the key position vector.
This function returns a vector of vectors of ints. Each vector contains the 37 assigned keyboard values for 1 channel. The indexs of these keys match the corresponding indexs for the key position vector.
| double MidiProcessor::get_song_duration | ( | ) |
gets the song duration
This function returns the duration of the song in seconds.
This function returns the duration of the song in seconds.

| bool MidiProcessor::load_json_file | ( | std::string | json_file_path | ) |
load JSON file
| [in] | std::string | - the name of the mipi file that should be loaded into the class variables (e.g. "filename.mipi") |
This function clears the class variables and repopulates all the variables with the data from selected mipi file.


|
private |
opens a selected midi file
| [in] | std::string | - the midi file path that is to be accessed and processed |
This function is called by the process_midi_file method. It opens and reads a midi file. It also runs a time analysis and a note on/off pairing method from the midifile library.


|
private |
processes and stores all notes that correspond to a specific channel
This function processes the notes for 1 channel at a time as specified by the input parameter storing them into the notes vector
This function processes the notes for 1 channel at a time as specified by the input parameter storing them into the notes vector

|
private |
processes and stores all notes and their timings and remove dud channels
This function is called by the process_midi_file method. It processes the notes along with their timestamps and durations (in seconds) for, storing them into the notes, note_timestamps, and note_durations vectors respectively. It then removes any channels with no notes
< list of dud channels


|
private |
processes and stores all instruments/channels
This function is called by the process_midi_file method. It extracts the instrument ID number for each channel from the midi file and stores it in the instruments vector


|
private |
process song duration
processes song duration
This function is called by the process_midi_file method. It extracts the songs maximum duration by analysing each channels delta times and converting them into seconds. Stores the duration in the "duration" variable.
This function is called by the process_midi_file method. It extracts the songs maximum duration by analysing each channels delta times and converting them into seconds. Stores the duration in the "duration" variable.


| int MidiProcessor::processMidiFile | ( | std::string | midi_file_path, |
| std::string | json_file_name | ||
| ) |
processes a midi file by saving all instruments (and their channels) to a set of vectors
| [in] | std::string | - midi_file_path The path to the midi file to be processed |
| [in] | std::string | - json_file_name The name of the json file to be saved |
This function opens the provided midi file, fully processes it, and saves all the data to a mipi file which can be reloaded. It is not neccesary to load a mipi file that was just processed as processing populates the variables.
| [in] | std::string | - midi_file_path The path to the midi file to be processed |
| [in] | std::string | - json_file_name The name of the json file to be saved |
This function opens the provided midi file, fully processes it, and saves all the data to a mipi file which can be reloaded. It is not neccesary to load a mipi file that was just processed as processing populates the variables.


|
private |
stores all data for current midi file in a storage file
| [in] | std::string | - the name of the file the data will be saved to. |
This function is called by the process_midi_file method. It creates a file of the specified name and saves all the data to it in a JSON format.


|
private |
note duration trimming function
This function is called by the process_midi_file method. It checks the durations of each note and whether they overlap with the next and if so it trims it down such that the note ends just before the next note starts.

|
private |
current list of assigned keys for each channel
|
private |
current list of channels
|
private |
current song duration
|
private |
home directory
|
private |
current list of instruments
|
private |
current list of keyboard indexs for each channel
|
private |
current list of keyboard values for each channel
|
private |
MidiFile library.
|
private |
minimum note duration
|
private |
minimum note gap
|
private |
current list of note_durations
|
private |
current list of note_timeStamps
|
private |
current list of notes