Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
midiPlayer.h
Go to the documentation of this file.
1#pragma once
2
55
56//==============================================================================
57// Includes
58//==============================================================================
59
60#include "swSynth.h"
61#include "midiFileParser.h"
62#include "cnfs_image.h"
63#include "hdw-dac.h"
64
65#include <stdint.h>
66#include <stdbool.h>
67#include <stddef.h>
68
69//==============================================================================
70// Defines
71//==============================================================================
72
73#define MIDI_CHANNEL_COUNT 16
74// The total number of pooled voices
75#define POOL_VOICE_COUNT 24
76// The number of voices reserved for percussion
77#define PERCUSSION_VOICES 16
78// The number of global MIDI players
79#define NUM_GLOBAL_PLAYERS 2
80// The index of the system-wide MIDI player for sound effects
81#define MIDI_SFX 0
82// The index of the system-wide MIDI player for background music
83#define MIDI_BGM 1
84// The maximum volume setting for globalMidiPlayerSetVolume()
85#define MAX_VOLUME 13
86
87#define MIDI_TRUE 0x7F
88#define MIDI_FALSE 0x00
89#define MIDI_TO_BOOL(val) (val > 63)
90#define BOOL_TO_MIDI(val) (val ? MIDI_TRUE : MIDI_FALSE)
91#define MIDI_DEF_HEADROOM 0x4000
92#define PITCH_BEND_CENTER 0x2000
93
95#define SAMPLES_TO_MIDI_TICKS(n, tempo, div) ((int64_t)(n) * 1000000 * (div) / DAC_SAMPLE_RATE_HZ / (tempo))
96
97#define SAMPLES_PER_TICK(tempo, div) ((uint64_t)DAC_SAMPLE_RATE_HZ * (tempo) / div / 1000000)
98
100#define TICKS_TO_SAMPLES(ticks, tempo, div) ((int64_t)(ticks) * DAC_SAMPLE_RATE_HZ / (1000000) * (tempo) / (div))
101
103#define SAMPLES_TO_MS(samp) (((samp) * 1000) / DAC_SAMPLE_RATE_HZ)
104
106#define SAMPLES_TO_US(samp) (((samp) * 1000000) / DAC_SAMPLE_RATE_HZ)
107
109#define MS_TO_SAMPLES(ms) ((ms) * DAC_SAMPLE_RATE_HZ / 1000)
110
112#define MIDI_TICKS_TO_US(ticks, tempo, div) (int64_t)((int64_t)((int64_t)(ticks) * (int64_t)(tempo)) / ((int64_t)(div)))
113
115typedef void (*songFinishedCbFn)(void);
116
117//==============================================================================
118// Enums
119//==============================================================================
120
133
147
151typedef enum
152{
160
170
190
194typedef enum
195{
196 // Roland GS Extensions
197 /*HIGH_Q_OR_FILTER_SNAP = 27,
198 SLAP_NOISE = 28,
199 SCRATCH_PUSH = 29,
200 SCRATCH_PULL = 30,
201 DRUM_STICKS = 31,
202 SQUARE_CLICK = 32,
203 METRONOME_CLICK = 33,
204 METRONOME_BELL = 34,*/
205 // End Roland GS Extensions
243 CABASA = 69,
253 CLAVES = 75,
264 // Roland GS Extensions
265 /*SHAKER = 82,
266 JINGLE_BELL = 83,
267 BELLTREE = 84,
268 CASTANETS = 85,
269 MUTE_SURDO = 86,
270 OPEN_SURDO = 87,*/
271 // End Roland GS Extensions
273
283typedef enum
284{
288
294
299
304
308
314
319
320 //< Switch
322 //< Switch
324 //< Switch
326 //< Switch
328 //< Switch
330 //< Switch
337 // Decay
339 // Sustain level
344 //< Switch
346 //< Switch
348 //< Switch
350 //< Switch
352
364
365 //< No data
367 //< No data
369 //< Switch
371 //< No data
373 //< No data
375 //< No data
377 //< No data
379 //< No data
382
392
393//==============================================================================
394// Structs
395//==============================================================================
396
401typedef struct
402{
404 int32_t attackTime;
405
408
410 int32_t decayTime;
411
414
416 int32_t releaseTime;
417
420
422 uint8_t sustainVol;
423
426
428 // uint32_t loopStart;
430 // uint32_t loopEnd;
431
432} envelope_t;
433
434typedef struct
435{
437 uint8_t chorus;
439
449typedef int8_t (*percussionFunc_t)(percussionNote_t drum, uint32_t idx, bool* done, uint32_t scratch[4], void* data);
450
458typedef void (*midiTextCallback_t)(metaEventType_t type, const char* text, uint32_t length);
459
464typedef bool (*midiStreamingCallback_t)(midiEvent_t* event);
465
470typedef struct
471{
473 cnfsFileIdx_t fIdx;
474
476 uint32_t rate;
477
480
482 int8_t tune;
483
485 uint32_t loop;
486
488 uint32_t loopStart;
489
491 uint32_t loopEnd;
493
501
505typedef struct
506{
509
512
513 union
514 {
515 struct
516 {
518 uint16_t waveIndex;
519
522 };
523
524 timbreSample_t sample;
525
526 struct
527 {
529 const noteSampleMap_t* map;
531 size_t count;
532 } multiSample;
533
534 struct
535 {
539 void* data;
540 } playFunc;
541
543 oscillatorShape_t shape;
544 };
545
548
551
553 const char* name;
555
561typedef struct
562{
565
568
571
573 uint32_t voiceTick;
574
576 uint32_t sampleTick;
577
580
583
585 uint8_t note;
586
588 uint8_t velocity;
589
592 uint8_t channel;
593
596
597 union
598 {
599 struct
600 {
602 const uint8_t* data;
604 uint32_t length;
605
607 uint32_t rate;
608
610 uint32_t loopStart;
612 uint32_t loopEnd;
613
616
618 int8_t tune;
619
622
624 uint32_t loopsRemaining;
625
628 } sample;
629
630 struct
631 {
634 } wave;
635
636 struct
637 {
639 uint32_t scratch[4];
640 } playFunc;
641 };
642
646
652typedef struct
653{
655 uint32_t on;
656
658 uint32_t attack;
659
661 uint32_t sustain;
662
664 uint32_t decay;
665
667 uint32_t release;
668
670 uint32_t held;
671
673 uint32_t sustenuto;
675
679typedef struct
680{
682 uint16_t volume;
683
685 uint16_t bank;
686
688 uint8_t program;
689
692
695
698
701
703 uint16_t pitchBend;
704
707
709 bool held;
710
713
715 bool ignore;
717
803
809void midiPlayerInit(midiPlayer_t* player);
810
816void midiPlayerReset(midiPlayer_t* player);
817
825
832int32_t midiPlayerStep(midiPlayer_t* player);
833
842void midiPlayerFillBuffer(midiPlayer_t* player, uint8_t* samples, int16_t len);
843
852void midiPlayerFillBufferMulti(midiPlayer_t* players, uint8_t playerCount, uint8_t* samples, int16_t len);
853
859void midiAllSoundOff(midiPlayer_t* player);
860
871void midiResetChannelControllers(midiPlayer_t* player, uint8_t channel);
872
878void midiGmOn(midiPlayer_t* player);
879
885void midiGmOff(midiPlayer_t* player);
886
894void midiAllNotesOff(midiPlayer_t* player, uint8_t channel);
895
906void midiNoteOn(midiPlayer_t* player, uint8_t channel, uint8_t note, uint8_t velocity);
907
916void midiAfterTouch(midiPlayer_t* player, uint8_t channel, uint8_t note, uint8_t velocity);
917
926void midiNoteOff(midiPlayer_t* player, uint8_t channel, uint8_t note, uint8_t velocity);
927
935void midiSetProgram(midiPlayer_t* player, uint8_t channel, uint8_t program);
936
949void midiSustain(midiPlayer_t* player, uint8_t channel, uint8_t val);
950
961void midiSustenuto(midiPlayer_t* player, uint8_t channel, uint8_t val);
962
971void midiControlChange(midiPlayer_t* player, uint8_t channel, midiControl_t control, uint8_t val);
972
981uint8_t midiGetControlValue(midiPlayer_t* player, uint8_t channel, midiControl_t control);
982
991uint16_t midiGetControlValue14bit(midiPlayer_t* player, uint8_t channel, midiControl_t control);
992
1002void midiSetParameter(midiPlayer_t* player, uint8_t channel, bool registered, uint16_t param, uint16_t value);
1003
1014uint16_t midiGetParameterValue(midiPlayer_t* player, uint8_t channel, bool registered, uint16_t param);
1015
1029void midiPitchWheel(midiPlayer_t* player, uint8_t channel, uint16_t value);
1030
1037void midiSetTempo(midiPlayer_t* player, uint32_t tempo);
1038
1045void midiSetFile(midiPlayer_t* player, const midiFile_t* file);
1046
1053void midiPause(midiPlayer_t* player, bool pause);
1054
1066void midiSeek(midiPlayer_t* player, uint32_t ticks);
1067
1068//==============================================================================
1069// Global MIDI Player Functions
1070//==============================================================================
1071
1075void initGlobalMidiPlayer(void);
1076
1081void deinitGlobalMidiPlayer(void);
1082
1090void globalMidiPlayerFillBuffer(uint8_t* samples, int16_t len);
1091
1098void globalMidiPlayerPlaySong(midiFile_t* song, uint8_t trackType);
1099
1107void globalMidiPlayerPlaySongCb(midiFile_t* song, uint8_t trackType, songFinishedCbFn cb);
1108
1115void globalMidiPlayerSetVolume(uint8_t trackType, int32_t volumeSetting);
1116
1121void globalMidiPlayerPauseAll(void);
1122
1127void globalMidiPlayerResumeAll(void);
1128
1135void globalMidiPlayerStop(bool reset);
1136
1143void* globalMidiSave(void);
1144
1151void globalMidiRestore(void* data);
1152
1160midiPlayer_t* globalMidiPlayerGet(uint8_t trackType);
1161
1172const midiTimbre_t* getTimbreForProgram(bool percussion, uint8_t bank, uint8_t program);
1173
1185const midiVoice_t* soundNoteOn(midiPlayer_t* player, uint8_t chanId, uint8_t note, uint8_t velocity,
1186 const midiTimbre_t* timbre, bool percussion);
1187
1199void soundNoteOff(midiPlayer_t* player, uint8_t chanId, uint8_t note, uint8_t velocity, bool percussion);
1200
1207void soundVoiceRelease(midiPlayer_t* player, const midiVoice_t* voice);
1208
1215void soundVoiceOff(midiPlayer_t* player, const midiVoice_t* voice);
uint32_t uq24_8
unsigned 24 bits integer, 8 bits fraction
Definition fp_math.h:41
uint32_t uq8_24
unsigned 8 bits integer, 24 bits fraction
Definition fp_math.h:43
int32_t q24_8
24 bits integer, 8 bits fraction
Definition fp_math.h:36
int32_t q8_24
8 bits integer, 24 bits fraction
Definition fp_math.h:38
uint32_t uq16_16
unsigned 16 bits integer, 16 bits fraction
Definition fp_math.h:42
metaEventType_t
The possible types of meta-events.
Definition midiFileParser.h:34
Contains information for an entire MIDI event or non-MIDI meta-event.
Definition midiFileParser.h:236
Definition midiFileParser.h:110
Contains information which applies to the entire MIDI file.
Definition midiFileParser.h:87
int32_t releaseTime
Base time it takes to silence the note after release, in DAC samples.
Definition midiPlayer.h:416
uint32_t loopStart
The start of the loop portion of the sample.
Definition midiPlayer.h:488
void midiNoteOn(midiPlayer_t *player, uint8_t channel, uint8_t note, uint8_t velocity)
Begin playing a note on a given MIDI channel.
Definition midiPlayer.c:2109
q8_24 volRate
Rate-of-change of the volume per tick, can be positive or negative.
Definition midiPlayer.h:567
uint16_t midiGetControlValue14bit(midiPlayer_t *player, uint8_t channel, midiControl_t control)
Get the combined value of two MIDI control registers.
Definition midiPlayer.c:2606
uint32_t loop
0 to loop forever, or the number of loops to play
Definition midiPlayer.h:485
midiEvent_t pendingEvent
The next event in the MIDI file, which occurs after the current time.
Definition midiPlayer.h:780
bool paused
True when playback of the current file is paused.
Definition midiPlayer.h:789
q24_8 sustainVolVel
This value will be multiplied by the note velocity and added to the attack time.
Definition midiPlayer.h:425
void midiSustain(midiPlayer_t *player, uint8_t channel, uint8_t val)
Set the hold pedal status.
Definition midiPlayer.c:2296
uint32_t stateChangeTick
The next tick at which state will change.
Definition midiPlayer.h:579
void globalMidiRestore(void *data)
Resume MIDI playback from the state stored in the given pointer. The data will be freed after this ca...
Definition midiFileParser.c:1084
void midiResetChannelControllers(midiPlayer_t *player, uint8_t channel)
Reset all controllers on a MIDI channel.
Definition midiPlayer.c:1699
const noteSampleMap_t * map
A map of different samples to use.
bool registeredParameter
Whether selectedParameter represents a registered or non-registered parameter.
Definition midiPlayer.h:691
bool songEnding
If true, all events from the current song have been read and we are waiting for notes to end.
Definition midiPlayer.h:798
timbreType_t
The sample source for an instrument.
Definition midiPlayer.h:138
@ PLAY_FUNC
Definition midiPlayer.h:145
@ SAMPLE
Definition midiPlayer.h:141
@ WAVETABLE
Samples are generated by sampling a particular wave shape.
Definition midiPlayer.h:140
@ WAVE_SHAPE
Definition midiPlayer.h:143
@ MULTI_SAMPLE
Definition midiPlayer.h:144
@ NOISE
Definition midiPlayer.h:142
uint32_t tick
The current MIDI tick.
Definition midiPlayer.h:777
q24_8 releaseTimeVel
This value will be multiplied by the note velocity and added to the attack time.
Definition midiPlayer.h:419
envelope_t envelope
Definition midiPlayer.h:499
void midiGmOn(midiPlayer_t *player)
Activate General MIDI mode on a MIDI player.
Definition midiPlayer.c:1714
uint32_t tempo
The number of microseconds per quarter note.
Definition midiPlayer.h:786
void midiPlayerResetNewSong(midiPlayer_t *player)
Reset the MIDI player state by only doing the bare minimum. This is useful when playing multiple soun...
Definition midiPlayer.c:1468
uint32_t length
The number of samples in the data.
void globalMidiPlayerPlaySong(midiFile_t *song, uint8_t trackType)
Play a song on one of the system-wide MIDI players, either BGM or SFX.
Definition midiPlayer.c:2921
synthOscillator_t oscillator
uint32_t sustenuto
Bitfield of voices which are being held by the sustenuto pedal.
Definition midiPlayer.h:673
uint32_t held
Bitfield of voices which are being held by the pedal.
Definition midiPlayer.h:670
midiManufacturerId_t
Values that can be directly compared against midiSysexEvent_t::manufacturerId.
Definition midiPlayer.h:387
@ MMFR_EDUCATIONAL_USE
Definition midiPlayer.h:388
@ MMFR_UNIVERSAL_NON_REAL_TIME
Definition midiPlayer.h:389
@ MMFR_UNIVERSAL_REAL_TIME
Definition midiPlayer.h:390
int32_t midiPlayerStep(midiPlayer_t *player)
Calculate and return the next MIDI sample, stepping the player state forward by one sample.
Definition midiPlayer.c:1482
void midiAfterTouch(midiPlayer_t *player, uint8_t channel, uint8_t note, uint8_t velocity)
Change the velocity of a note on a given MIDI channel, after the note starts playing.
Definition midiPlayer.c:2130
q8_24 volAccel
Acceleration of the volume per tick, which will be added to the rate.
Definition midiPlayer.h:570
voiceStates_t poolVoiceStates
The global voice pool state bitmaps.
Definition midiPlayer.h:746
void midiPlayerFillBuffer(midiPlayer_t *player, uint8_t *samples, int16_t len)
Fill a buffer with the next set of samples from the MIDI player. This should be called by the callbac...
Definition midiPlayer.c:1574
midiTimbre_t timbre
The actual current timbre definition which the program ID corresponds to.
Definition midiPlayer.h:697
waveFunc_t waveFunc
The function to use to retrieve wavetable samples.
int32_t attackTime
Base time taken to ramp up to full volume.
Definition midiPlayer.h:404
timbreSample_t sample
Definition midiPlayer.h:498
midiVoice_t percVoices[PERCUSSION_VOICES]
The voices reserved for percussion.
Definition midiPlayer.h:730
const midiTimbre_t * getTimbreForProgram(bool percussion, uint8_t bank, uint8_t program)
Return a pointer to the predefined timbre assigned to the given bank and program IDs.
Definition midiPlayer.c:891
uq16_16 baseNote
The sample's base frequency.
voiceStates_t percVoiceStates
The percussion voice state bitmaps.
Definition midiPlayer.h:733
uint32_t loopStart
The sample number to return to after reaching the loop end.
uint32_t loopEnd
The end of the loop portion of the sample.
Definition midiPlayer.h:491
q24_8 attackTimeVel
This value will be multiplied by the note velocity and added to the attack time,.
Definition midiPlayer.h:407
timbreType_t type
The source of samples for this instrument.
Definition midiPlayer.h:508
uint32_t loopEnd
The sample number after which to return to the loop start.
void midiSetParameter(midiPlayer_t *player, uint8_t channel, bool registered, uint16_t param, uint16_t value)
Set a registered or non-registered parameter value.
Definition midiPlayer.c:2624
void midiSeek(midiPlayer_t *player, uint32_t ticks)
Seek to a given time offset within a file.
Definition midiPlayer.c:2784
voiceType_t
Enum which defines the method used to retrieve a sample from each voice.
Definition midiPlayer.h:165
@ VOICE_PLAY_FUNC
Definition midiPlayer.h:167
@ VOICE_WAVE_FUNC
Definition midiPlayer.h:166
@ VOICE_SAMPLE
Definition midiPlayer.h:168
void deinitGlobalMidiPlayer(void)
Deinitialize and free memory associated with the system-wide MIDI players.
Definition midiPlayer.c:2893
void globalMidiPlayerStop(bool reset)
Stop all songs currently being played by the system-wide MIDI players, optionally resetting their sta...
Definition midiPlayer.c:2987
bool held
Whether notes will be held after release.
Definition midiPlayer.h:709
uint32_t percSpecialStates
A bitmap to track which percussion voices have special notes playing This includes all 3 hi-hats (ope...
Definition midiPlayer.h:740
void midiSustenuto(midiPlayer_t *player, uint8_t channel, uint8_t val)
Set the sustenuto pedal status.
Definition midiPlayer.c:2343
uq16_16 pitch
The ultimate pitch of this voice after pitch bending, etc.
Definition midiPlayer.h:582
void midiSetProgram(midiPlayer_t *player, uint8_t channel, uint8_t program)
Change the program (instrument) on a given MIDI channel.
Definition midiPlayer.c:2279
uq24_8 sampleRateRatio
The pre-calculated samples-per-second.
bool loop
If true, the playing file will automatically repeat when complete.
Definition midiPlayer.h:795
adsrState_t
Enum representing specific ADSR states.
Definition midiPlayer.h:176
@ ADSR_ON
On, in which the note is on but doesn't have any specific ADSR states set (what?)
Definition midiPlayer.h:178
@ ADSR_RELEASE
Release, in which the volume falls from the sustain volume to 0 quadratically.
Definition midiPlayer.h:186
@ ADSR_OFF
Off, in which the note has finished playing completely.
Definition midiPlayer.h:188
@ ADSR_DECAY
Decay, in which the volume falls from the max volume to the sustain volume linearly.
Definition midiPlayer.h:182
@ ADSR_ATTACK
Attack, in which the volume rises from 0 to the max volume linearly.
Definition midiPlayer.h:180
@ ADSR_SUSTAIN
Sustain, in which the volume remains at the sustain volume.
Definition midiPlayer.h:184
bool sustenuto
Whether certain notes will be held after release.
Definition midiPlayer.h:712
midiFileReader_t reader
A MIDI reader to use for file playback, when in MIDI_FILE mode.
Definition midiPlayer.h:752
uint32_t rate
The number of samples per second of raw sample data.
uint8_t velocity
The MIDI note velocity of the playing note.
Definition midiPlayer.h:588
void soundVoiceRelease(midiPlayer_t *player, const midiVoice_t *voice)
Transition the given voice into the 'release' state, equivalent to a MIDI Note Off.
Definition midiPlayer.c:2083
void midiPlayerInit(midiPlayer_t *player)
Initialize the MIDI player.
Definition midiPlayer.c:1434
uint8_t channel
The index of the MIDI channel that owns the currently playing note. If 255 or any other value >= 16,...
Definition midiPlayer.h:592
uint8_t sustainVol
The base volume of the sustained note, proportional to the sample volume.
Definition midiPlayer.h:422
uq8_24 curVol
The current volume as a fixed-point value.
Definition midiPlayer.h:564
void globalMidiPlayerResumeAll(void)
Resume all songs currently being played by the system-wide MIDI players.
Definition midiPlayer.c:2976
#define PERCUSSION_VOICES
Definition midiPlayer.h:77
int32_t headroom
The constant value to multiply each frame's samples by, before being shifted right 16 bits This value...
Definition midiPlayer.h:767
void globalMidiPlayerFillBuffer(uint8_t *samples, int16_t len)
Fill the given sample buffer with samples from both the BGM and SFX system-wide MIDI players.
Definition midiPlayer.c:2909
void midiPitchWheel(midiPlayer_t *player, uint8_t channel, uint16_t value)
Set the pitch wheel value on a given MIDI channel.
Definition midiPlayer.c:2712
uint32_t attack
Bitfield of voices currently in the attack stage.
Definition midiPlayer.h:658
void midiGmOff(midiPlayer_t *player)
Deactivate General MIDI mode on a MIDI player.
Definition midiPlayer.c:1730
uint8_t note
The MIDI note number for the sound being played.
Definition midiPlayer.h:585
int8_t tune
The sample's fine tuning.
percussionFunc_t func
A callback to call for drum data.
void midiNoteOff(midiPlayer_t *player, uint8_t channel, uint8_t note, uint8_t velocity)
Stop playing a particular note on a given MIDI channel.
Definition midiPlayer.c:2215
#define POOL_VOICE_COUNT
Definition midiPlayer.h:75
uint32_t rate
The sample rate.
Definition midiPlayer.h:476
midiPlayerMode_t
Represents the source of MIDI data.
Definition midiPlayer.h:126
@ MIDI_STREAMING
Streaming over USB.
Definition midiPlayer.h:128
@ MIDI_FILE
Reading from a midiFileReader_t.
Definition midiPlayer.h:131
midiVoice_t poolVoices[POOL_VOICE_COUNT]
The global voice pool for non-percussion channels.
Definition midiPlayer.h:743
uint32_t decay
Bitfield of voices currently in the decay stage.
Definition midiPlayer.h:664
bool percussion
Whether this channel is reserved for percussion.
Definition midiPlayer.h:706
void globalMidiPlayerPauseAll(void)
Pause all songs currently being played by the system-wide MIDI players.
Definition midiPlayer.c:2965
int32_t decayTime
Base time taken for the volume to fade to the sustain volume.
Definition midiPlayer.h:410
uint32_t clipped
Number of samples that were clipped Note: This is not set when using midiPlayerFillBufferMulti()
Definition midiPlayer.h:771
void * data
User data to pass to the drumkit.
void midiAllSoundOff(midiPlayer_t *player)
Stop all sound immediately. This is not affected by the sustain pedal.
Definition midiPlayer.c:1643
const char * name
The name of this timbre, if any.
Definition midiPlayer.h:553
void(* midiTextCallback_t)(metaEventType_t type, const char *text, uint32_t length)
A function to handle text meta-messages from playing MIDI files.
Definition midiPlayer.h:458
#define MIDI_CHANNEL_COUNT
Definition midiPlayer.h:73
bool eventAvailable
True if pendingEvent is valid, false if it must be updated.
Definition midiPlayer.h:783
midiTextCallback_t textMessageCallback
A callback to call when a text meta-message is received.
Definition midiPlayer.h:758
uint64_t sampleCount
The number of samples elapsed in the playing song.
Definition midiPlayer.h:774
q24_8 decayTimeVel
This value will be multiplied by the note velocity and added to the decay time.
Definition midiPlayer.h:413
uint32_t allocedVoices
A bitmap of which voices have been allocated to this channel.
Definition midiPlayer.h:700
uint16_t selectedParameter
The ID of the currently selected registered or non-registered parameter.
Definition midiPlayer.h:694
void midiAllNotesOff(midiPlayer_t *player, uint8_t channel)
Tun off all notes which are currently on, as though midiNoteOff() were called for each note....
Definition midiPlayer.c:1782
uint32_t release
Bitfield of voices currently in the release stage.
Definition midiPlayer.h:667
void soundNoteOff(midiPlayer_t *player, uint8_t chanId, uint8_t note, uint8_t velocity, bool percussion)
Stop playing a single note with custom MIDI parameters.
Definition midiPlayer.c:2013
const midiVoice_t * soundNoteOn(midiPlayer_t *player, uint8_t chanId, uint8_t note, uint8_t velocity, const midiTimbre_t *timbre, bool percussion)
Play a single note with custom MIDI parameters, without affecting any existing channel settings.
Definition midiPlayer.c:1800
bool seeking
True when the MIDI player is seeking, and will not produce sound.
Definition midiPlayer.h:792
uint8_t midiGetControlValue(midiPlayer_t *player, uint8_t channel, midiControl_t control)
Get the value of a MIDI control.
Definition midiPlayer.c:2568
midiChannel_t channels[MIDI_CHANNEL_COUNT]
The state of all MIDI channels.
Definition midiPlayer.h:727
void globalMidiPlayerPlaySongCb(midiFile_t *song, uint8_t trackType, songFinishedCbFn cb)
Play a song on one of the system-wide MIDI players, with a callback once the song finishes.
Definition midiPlayer.c:2935
void soundVoiceOff(midiPlayer_t *player, const midiVoice_t *voice)
Immediately stop a single voice from playing, disregarding all ADSR parameters.
Definition midiPlayer.c:2058
uint16_t bank
The bank to use for program changes on this channel.
Definition midiPlayer.h:685
uint16_t waveIndex
The index of this timbre's wave in the table, when type is WAVETABLE.
uint8_t program
The ID of the program (timbre) set for this channel.
Definition midiPlayer.h:688
uint8_t noteEnd
Definition midiPlayer.h:497
uint32_t on
Whether this note is set to on via MIDI, regardless of if it's making sound.
Definition midiPlayer.h:655
void midiControlChange(midiPlayer_t *player, uint8_t channel, midiControl_t control, uint8_t val)
Set a MIDI control value.
Definition midiPlayer.c:2386
midiPlayerMode_t mode
Whether this player is playing a song or a MIDI stream.
Definition midiPlayer.h:749
uint16_t volume
The 14-bit volume level for this channel only.
Definition midiPlayer.h:682
uint8_t noteStart
Definition midiPlayer.h:496
void midiSetFile(midiPlayer_t *player, const midiFile_t *file)
Configure this MIDI player to read from a MIDI file.
Definition midiPlayer.c:2759
songFinishedCbFn songFinishedCallback
A callback to call when the playing song is finished.
Definition midiPlayer.h:761
void initGlobalMidiPlayer(void)
Initialize the system-wide MIDI players for both BGM and SFX.
Definition midiPlayer.c:2881
uq24_8 error
The number of fractional samples remaining.
bool forceCheckEvents
Force a check for MIDI events on the next sample.
Definition midiPlayer.h:801
timbreFlags_t flags
Flags bitfield for this timbre.
Definition midiPlayer.h:511
void midiPause(midiPlayer_t *player, bool pause)
Set the paused state of a MIDI song.
Definition midiPlayer.c:2779
midiControl_t
Defines the MIDI continuous controller registers.
Definition midiPlayer.h:284
@ MCC_GP_BUTTON_1
Definition midiPlayer.h:345
@ MCC_PAN_LSB
Definition midiPlayer.h:315
@ MCC_OMNI_MODE_ON
Definition midiPlayer.h:376
@ MCC_EFFECT_1_MSB
Definition midiPlayer.h:297
@ MCC_DETUNE_LEVEL
Definition midiPlayer.h:356
@ MCC_BREATH_LSB
Definition midiPlayer.h:307
@ MCC_BANK_LSB
Definition midiPlayer.h:305
@ MCC_MODULATION_WHEEL_MSB
Definition midiPlayer.h:286
@ MCC_PORTAMENTO
Definition midiPlayer.h:323
@ MCC_SOUND_CONTROL_10
Definition midiPlayer.h:343
@ MCC_GP_SLIDER_4
Definition midiPlayer.h:303
@ MCC_FOOT_PEDAL_MSB
Definition midiPlayer.h:289
@ MCC_BALANCE_MSB
Definition midiPlayer.h:293
@ MCC_LOCAL_KEYBOARD
Definition midiPlayer.h:370
@ MCC_FOOT_PEDAL_LSB
Definition midiPlayer.h:309
@ MCC_PAN_MSB
Definition midiPlayer.h:295
@ MCC_SOUND_CONTROL_7
Definition midiPlayer.h:340
@ MCC_REGISTERED_PARAM_MSB
Definition midiPlayer.h:363
@ MCC_VOLUME_LSB
Definition midiPlayer.h:312
@ MCC_OMNI_MODE_OFF
Definition midiPlayer.h:374
@ MCC_HOLD_PEDAL
Definition midiPlayer.h:321
@ MCC_GP_BUTTON_2
Definition midiPlayer.h:347
@ MCC_NON_REGISTERED_PARAM_MSB
Definition midiPlayer.h:361
@ MCC_GP_SLIDER_2
Definition midiPlayer.h:301
@ MCC_ALL_SOUND_OFF
Definition midiPlayer.h:366
@ MCC_HOLD_2_PEDAL
Definition midiPlayer.h:331
@ MCC_PORTAMENTO_TIME_MSB
Definition midiPlayer.h:290
@ MCC_DATA_BUTTON_DEC
Definition midiPlayer.h:359
@ MCC_LEGATO_PEDAL
Definition midiPlayer.h:329
@ MCC_PORTAMENTO_TIME_LSB
Definition midiPlayer.h:310
@ MCC_SOUND_CONTROL_8
Definition midiPlayer.h:341
@ MCC_EFFECT_2_LSB
Definition midiPlayer.h:318
@ MCC_DATA_ENTRY_LSB
Definition midiPlayer.h:311
@ MCC_VOLUME_MSB
Definition midiPlayer.h:292
@ MCC_DATA_BUTTON_INC
Definition midiPlayer.h:358
@ MCC_BREATH_MSB
Definition midiPlayer.h:287
@ MCC_EFFECT_2_MSB
Definition midiPlayer.h:298
@ MCC_SOFT_PEDAL
Definition midiPlayer.h:327
@ MCC_SOUND_VARIATION
Definition midiPlayer.h:332
@ MCC_PHASER_LEVEL
Definition midiPlayer.h:357
@ MCC_CHORUS_LEVEL
Definition midiPlayer.h:355
@ MCC_EFFECT_1_LSB
Definition midiPlayer.h:317
@ MCC_DATA_ENTRY_MSB
Definition midiPlayer.h:291
@ MCC_ALL_CONTROLS_OFF
Definition midiPlayer.h:368
@ MCC_BANK_MSB
Definition midiPlayer.h:285
@ MCC_BALANCE_LSB
Definition midiPlayer.h:313
@ MCC_EXPRESSION_LSB
Definition midiPlayer.h:316
@ MCC_GP_BUTTON_4
Definition midiPlayer.h:351
@ MCC_SOUND_BRIGHTNESS
Definition midiPlayer.h:336
@ MCC_SOUND_TIMBRE
Definition midiPlayer.h:333
@ MCC_SOUND_CONTROL_9
Definition midiPlayer.h:342
@ MCC_MODULATION_WHEEL_LSB
Definition midiPlayer.h:306
@ MCC_GP_SLIDER_3
Definition midiPlayer.h:302
@ MCC_SOUND_ATTACK_TIME
Definition midiPlayer.h:335
@ MCC_SOUND_RELEASE_TIME
Definition midiPlayer.h:334
@ MCC_REGISTERED_PARAM_LSB
Definition midiPlayer.h:362
@ MCC_NON_REGISTERED_PARAM_LSB
Definition midiPlayer.h:360
@ MCC_MONO_OPERATION
Definition midiPlayer.h:378
@ MCC_ALL_NOTE_OFF
Definition midiPlayer.h:372
@ MCC_TREMOLO_LEVEL
Definition midiPlayer.h:354
@ MCC_EFFECTS_LEVEL
Definition midiPlayer.h:353
@ MCC_SOUND_CONTROL_6
Definition midiPlayer.h:338
@ MCC_SUSTENUTO_PEDAL
Definition midiPlayer.h:325
@ MCC_POLY_OPERATION
Definition midiPlayer.h:380
@ MCC_EXPRESSION_MSB
Definition midiPlayer.h:296
@ MCC_GP_SLIDER_1
Definition midiPlayer.h:300
@ MCC_GP_BUTTON_3
Definition midiPlayer.h:349
uint32_t sampleTick
The non-monotonic tick counter for playback of sampled timbres.
Definition midiPlayer.h:576
uint16_t midiGetParameterValue(midiPlayer_t *player, uint8_t channel, bool registered, uint16_t param)
Get the value of a registered or non-registered parameter.
Definition midiPlayer.c:2685
cnfsFileIdx_t fIdx
The file index containing the sample data.
Definition midiPlayer.h:473
void(* songFinishedCbFn)(void)
Callback function used to provide feedback when a song finishes playing.
Definition midiPlayer.h:115
bool ignore
If set, events on this channel will be completely ignored.
Definition midiPlayer.h:715
uint32_t sustain
Bitfield of voices currently in the sustain stage.
Definition midiPlayer.h:661
percussionNote_t
Defines the MIDI note numbers mapped to by the General MIDI percussion note names.
Definition midiPlayer.h:195
@ OPEN_TRIANGLE
This note supersedes any MUTE_TRIANGLE or OPEN_TRIANGLE notes playing.
Definition midiPlayer.h:263
@ COWBELL
Definition midiPlayer.h:230
@ ACOUSTIC_SNARE
Definition midiPlayer.h:209
@ CLOSED_HI_HAT
This note supersedes any CLOSED_HI_HAT, PEDAL_HI_HAT, or OPEN_HI_HAT notes playing.
Definition midiPlayer.h:214
@ LOW_BONGO
Definition midiPlayer.h:235
@ HIGH_BONGO
Definition midiPlayer.h:234
@ CHINESE_CYMBAL
Definition midiPlayer.h:226
@ RIDE_CYMBAL_2
Definition midiPlayer.h:233
@ LONG_GUIRO
This note supersedes any SHORT_GUIRO or LONG_GUIRO notes playing.
Definition midiPlayer.h:252
@ RIDE_BELL
Definition midiPlayer.h:227
@ SHORT_GUIRO
This note supersedes any SHORT_GUIRO or LONG_GUIRO notes playing.
Definition midiPlayer.h:250
@ HIGH_TOM
Definition midiPlayer.h:224
@ MUTE_CUICA
This note supersedes any SHORT_GUIRO or LONG_GUIRO notes playing.
Definition midiPlayer.h:257
@ CABASA
Definition midiPlayer.h:243
@ CRASH_CYMBAL_2
Definition midiPlayer.h:231
@ CRASH_CYMBAL_1
Definition midiPlayer.h:223
@ LOW_MID_TOM
Definition midiPlayer.h:221
@ LOW_AGOGO
Definition midiPlayer.h:242
@ HIGH_TIMBALE
Definition midiPlayer.h:239
@ SIDE_STICK
Definition midiPlayer.h:208
@ RIDE_CYMBAL_1
Definition midiPlayer.h:225
@ ELECTRIC_SNARE_OR_RIMSHOT
Definition midiPlayer.h:211
@ CLAVES
Definition midiPlayer.h:253
@ OPEN_HIGH_CONGA
Definition midiPlayer.h:237
@ LONG_WHISTLE
This note supersedes any SHORT_WHISTLE or LONG_WHISTLE notes playing.
Definition midiPlayer.h:248
@ LOW_TOM
Definition midiPlayer.h:218
@ HIGH_AGOGO
Definition midiPlayer.h:241
@ TAMBOURINE
Definition midiPlayer.h:228
@ HIGH_MID_TOM
Definition midiPlayer.h:222
@ MUTE_HIGH_CONGA
Definition midiPlayer.h:236
@ SPLASH_CYMBAL
Definition midiPlayer.h:229
@ HIGH_WOODBLOCK
Definition midiPlayer.h:254
@ LOW_FLOOR_TOM
Definition midiPlayer.h:212
@ VIBRASLAP
Definition midiPlayer.h:232
@ SHORT_WHISTLE
This note supersedes any SHORT_WHISTLE or LONG_WHISTLE notes playing.
Definition midiPlayer.h:246
@ PEDAL_HI_HAT
This note supersedes any CLOSED_HI_HAT, PEDAL_HI_HAT, or OPEN_HI_HAT notes playing.
Definition midiPlayer.h:217
@ LOW_CONGA
Definition midiPlayer.h:238
@ LOW_TIMBALE
Definition midiPlayer.h:240
@ OPEN_CUICA
This note supersedes any SHORT_GUIRO or LONG_GUIRO notes playing.
Definition midiPlayer.h:259
@ ELECTRIC_BASS_DRUM_OR_HIGH_BASS_DRUM
Definition midiPlayer.h:207
@ LOW_WOODBLOCK
Definition midiPlayer.h:255
@ HIGH_FLOOR_TOM
Definition midiPlayer.h:215
@ MARACAS
Definition midiPlayer.h:244
@ HAND_CLAP
Definition midiPlayer.h:210
@ MUTE_TRIANGLE
This note supersedes any MUTE_TRIANGLE or OPEN_TRIANGLE notes playing.
Definition midiPlayer.h:261
@ OPEN_HI_HAT
This note supersedes any CLOSED_HI_HAT, PEDAL_HI_HAT, or OPEN_HI_HAT notes playing.
Definition midiPlayer.h:220
@ ACOUSTIC_BASS_DRUM_OR_LOW_BASS_DRUM
Definition midiPlayer.h:206
uint8_t chorus
The number of chorused voices to mix.
Definition midiPlayer.h:437
void globalMidiPlayerSetVolume(uint8_t trackType, int32_t volumeSetting)
Set the volume using a value from 0 to 13.
Definition midiPlayer.c:2944
void midiPlayerFillBufferMulti(midiPlayer_t *players, uint8_t playerCount, uint8_t *samples, int16_t len)
Fill a buffer with the next set of samples from an array of MIDI players.
Definition midiPlayer.c:1608
size_t count
The length of the sample map.
uint32_t loopsRemaining
The number of loops remaining before the voice will transition to the released state.
midiPlayer_t * globalMidiPlayerGet(uint8_t trackType)
Return a pointer to the system-wide MIDI player for the given track type, either MIDI_SFX or MIDI_BGM...
Definition midiPlayer.c:3005
uint16_t pitchBend
The 14-bit pitch wheel value.
Definition midiPlayer.h:703
bool(* midiStreamingCallback_t)(midiEvent_t *event)
A function to return MIDI events in streaming mode.
Definition midiPlayer.h:464
void midiSetTempo(midiPlayer_t *player, uint32_t tempo)
Change the MIDI playback tempo.
Definition midiPlayer.c:2749
void * globalMidiSave(void)
Stop all MIDI playback and return a pointer containing the full playback state. This state must be pa...
Definition midiFileParser.c:1049
uq8_24 baseNote
The base frequency, at which the sample plays at normal speed.
Definition midiPlayer.h:479
uint32_t voiceTick
The monotonic tick counter for this voice since starting.
Definition midiPlayer.h:573
int8_t(* percussionFunc_t)(percussionNote_t drum, uint32_t idx, bool *done, uint32_t scratch[4], void *data)
A function that returns samples for a percussion timbre rather than a melodic one.
Definition midiPlayer.h:449
int8_t tune
Fine tuning of the note, +/- 100 cents.
Definition midiPlayer.h:482
void midiPlayerReset(midiPlayer_t *player)
Reset the MIDI player state.
Definition midiPlayer.c:1443
voiceType_t type
The method for obtaining the next audio sample.
Definition midiPlayer.h:595
midiStreamingCallback_t streamingCallback
A callback function to retrieve the next event, when in MIDI_STREAMING mode.
Definition midiPlayer.h:755
timbreFlags_t
A bitfield which may contain various flags for a timbre.
Definition midiPlayer.h:152
@ TF_PERCUSSION
This timbre plays percussion sounds (percussionNote_t) rather than melodic notes.
Definition midiPlayer.h:156
@ TF_MONO
This timbre represents a monophonic instrument.
Definition midiPlayer.h:158
@ TF_NONE
No flags.
Definition midiPlayer.h:154
timbreEffects_t effects
Various effects applied to this timbre. May be ignored by percussion timbres.
Definition midiPlayer.h:550
Describes the characteristics of a particular timbre while.
Definition midiPlayer.h:402
Tracks the state of a single MIDI channel.
Definition midiPlayer.h:680
Tracks the state of the entire MIDI apparatus.
Definition midiPlayer.h:722
Defines the sound characteristics of a particular instrument.
Definition midiPlayer.h:506
Tracks the state of a single voice, playing a single note.
Definition midiPlayer.h:562
Definition midiPlayer.h:495
Definition midiPlayer.h:435
Struct that holds information about a sample that can be played.
Definition midiPlayer.h:471
Holds several bitfields that track the state of each voice for fast access. This may be used for dyna...
Definition midiPlayer.h:653
oscillatorShape_t
The different wave shapes that can be generated.
Definition swSynth.h:65
int8_t(* waveFunc_t)(uint16_t idx, void *data)
Function typedef to return a sample from a wave.
Definition swSynth.h:97
A software oscillator with controllable frequency, amplitude, and shape.
Definition swSynth.h:107