Split MIDI functionality into MIDI_BASIC and MIDI_ADVANCED

MIDI_ENABLE = no

   text	   data	    bss	    dec	    hex	filename
      0	  17080	      0	  17080	   42b8	satan_midi.hex

MIDI_ENABLE = yes
MIDI_BASIC undefined
MIDI_ADVANCED undefined

   text	   data	    bss	    dec	    hex	filename
      0	  19494	      0	  19494	   4c26	satan_midi.hex

MIDI_ENABLE = yes
#define MIDI_BASIC
MIDI_ADVANCED undefined

   text	   data	    bss	    dec	    hex	filename
      0	  19788	      0	  19788	   4d4c	satan_midi.hex

MIDI_ENABLE = yes
MIDI_BASIC undefined
#define MIDI_ADVANCED

   text	   data	    bss	    dec	    hex	filename
      0	  20846	      0	  20846	   516e	satan_midi.hex

MIDI_ENABLE = yes
#define MIDI_BASIC
#define MIDI_ADVANCED

   text	   data	    bss	    dec	    hex	filename
      0	  21140	      0	  21140	   5294	satan_midi.hex
example_keyboards
Gabriel Young 8 years ago
parent 64eecfc530
commit 525be99ee9

@ -141,6 +141,7 @@ endif
ifeq ($(strip $(MIDI_ENABLE)), yes) ifeq ($(strip $(MIDI_ENABLE)), yes)
OPT_DEFS += -DMIDI_ENABLE OPT_DEFS += -DMIDI_ENABLE
SRC += $(QUANTUM_DIR)/process_keycode/process_music.c
SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c
endif endif

@ -3,7 +3,22 @@
#include "../../config.h" #include "../../config.h"
// place overrides here /*
* MIDI options
*/
/* enable basic MIDI features:
- MIDI notes can be sent when in Music mode is on
*/
#define MIDI_BASIC
/* enable advanced MIDI features:
- MIDI notes can be added to the keymap
- Octave shift and transpose
- Virtual sustain, portamento, and modulation wheel
- etc.
*/
#define MIDI_ADVANCED
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ /* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
#define MIDI_TONE_KEYCODE_OCTAVES 2 #define MIDI_TONE_KEYCODE_OCTAVES 2

@ -32,7 +32,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT, \ KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT, \
KC_LCTL, KC_LGUI,KC_LALT, KC_SPC, KC_RALT,KC_RGUI, TG(_ML), KC_RCTL), KC_LCTL, KC_LGUI,KC_LALT, KC_SPC, KC_RALT,KC_RGUI, TG(_ML), KC_RCTL),
#ifdef MIDI_ENABLE #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
/* Keymap _ML: MIDI Layer /* Keymap _ML: MIDI Layer
* ,------------------------------------------------------------------------. * ,------------------------------------------------------------------------.
* | Exit | | | | | | | | | | | | | | * | Exit | | | | | | | | | | | | | |
@ -51,6 +51,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
MI_CHU, XXXXXXX, MI_Cs, MI_Ds, XXXXXXX, MI_Fs, MI_Gs, MI_As, XXXXXXX, MI_Cs_1, MI_Ds_1, XXXXXXX, XXXXXXX, XXXXXXX, \ MI_CHU, XXXXXXX, MI_Cs, MI_Ds, XXXXXXX, MI_Fs, MI_Gs, MI_As, XXXXXXX, MI_Cs_1, MI_Ds_1, XXXXXXX, XXXXXXX, XXXXXXX, \
MI_MOD, MI_C, MI_D, MI_E, MI_F, MI_G, MI_A, MI_B, MI_C_1, MI_D_1, MI_E_1, MI_F_1, _______, \ MI_MOD, MI_C, MI_D, MI_E, MI_F, MI_G, MI_A, MI_B, MI_C_1, MI_D_1, MI_E_1, MI_F_1, _______, \
MI_SUS, MI_OCTD, MI_OCTU, MI_MODSD, MI_MODSU, XXXXXXX, XXXXXXX, XXXXXXX, MI_TRNSD, MI_TRNSU, MI_TRNS_0, MI_SUS, \ MI_SUS, MI_OCTD, MI_OCTU, MI_MODSD, MI_MODSU, XXXXXXX, XXXXXXX, XXXXXXX, MI_TRNSD, MI_TRNSU, MI_TRNS_0, MI_SUS, \
_______, _______, _______, MI_OFF, _______, _______, _______, _______), _______, _______, _______, MI_ALLOFF, _______, _______, _______, _______),
#endif #endif
}; };

@ -1,6 +1,7 @@
#define MIDI_TONE_KEYCODE_OCTAVES 2
#include "process_midi.h" #include "process_midi.h"
#if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
#include "timer.h" #include "timer.h"
static uint8_t tone_status[MIDI_TONE_COUNT]; static uint8_t tone_status[MIDI_TONE_COUNT];
@ -161,7 +162,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
dprintf("midi channel %d\n", midi_config.channel); dprintf("midi channel %d\n", midi_config.channel);
} }
return false; return false;
case MI_OFF: case MI_ALLOFF:
if (record->event.pressed) { if (record->event.pressed) {
midi_send_cc(&midi_device, midi_config.channel, 0x7B, 0); midi_send_cc(&midi_device, midi_config.channel, 0x7B, 0);
dprintf("midi off\n"); dprintf("midi off\n");
@ -209,3 +210,5 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
return true; return true;
} }
#endif // MIDI_ADVANCED

@ -17,6 +17,7 @@ static uint16_t music_sequence_interval = 100;
bool process_music(uint16_t keycode, keyrecord_t *record) { bool process_music(uint16_t keycode, keyrecord_t *record) {
#ifdef AUDIO_ENABLE
if (keycode == AU_ON && record->event.pressed) { if (keycode == AU_ON && record->event.pressed) {
audio_on(); audio_on();
return false; return false;
@ -38,6 +39,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
} }
return false; return false;
} }
#endif // AUDIO_ENABLE
if (keycode == MU_ON && record->event.pressed) { if (keycode == MU_ON && record->event.pressed) {
music_on(); music_on();
@ -61,6 +63,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
return false; return false;
} }
#ifdef AUDIO_ENABLE
if (keycode == MUV_IN && record->event.pressed) { if (keycode == MUV_IN && record->event.pressed) {
voice_iterate(); voice_iterate();
music_scale_user(); music_scale_user();
@ -72,11 +75,14 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
music_scale_user(); music_scale_user();
return false; return false;
} }
#endif // AUDIO_ENABLE
if (music_activated) { if (music_activated) {
if (keycode == KC_LCTL && record->event.pressed) { // Start recording if (keycode == KC_LCTL && record->event.pressed) { // Start recording
#ifdef AUDIO_ENABLE
stop_all_notes(); stop_all_notes();
#endif
music_sequence_recording = true; music_sequence_recording = true;
music_sequence_recorded = false; music_sequence_recorded = false;
music_sequence_playing = false; music_sequence_playing = false;
@ -85,7 +91,9 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
} }
if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing
#ifdef AUDIO_ENABLE
stop_all_notes(); stop_all_notes();
#endif
if (music_sequence_recording) { // was recording if (music_sequence_recording) { // was recording
music_sequence_recorded = true; music_sequence_recorded = true;
} }
@ -95,7 +103,9 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
} }
if (keycode == KC_LGUI && record->event.pressed && music_sequence_recorded) { // Start playing if (keycode == KC_LGUI && record->event.pressed && music_sequence_recorded) { // Start playing
#ifdef AUDIO_ENABLE
stop_all_notes(); stop_all_notes();
#endif
music_sequence_recording = false; music_sequence_recording = false;
music_sequence_playing = true; music_sequence_playing = true;
music_sequence_position = 0; music_sequence_position = 0;
@ -116,6 +126,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
} }
#define MUSIC_MODE_GUITAR #define MUSIC_MODE_GUITAR
#ifdef AUDIO_ENABLE
#ifdef MUSIC_MODE_CHROMATIC #ifdef MUSIC_MODE_CHROMATIC
float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(MATRIX_ROWS - record->event.key.row)); float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(MATRIX_ROWS - record->event.key.row));
#elif defined(MUSIC_MODE_GUITAR) #elif defined(MUSIC_MODE_GUITAR)
@ -125,15 +136,20 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
#else #else
float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + SCALE[record->event.key.col + music_offset])/12.0+(MATRIX_ROWS - record->event.key.row)); float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + SCALE[record->event.key.col + music_offset])/12.0+(MATRIX_ROWS - record->event.key.row));
#endif #endif
#endif // AUDIO_ENABLE
if (record->event.pressed) { if (record->event.pressed) {
#ifdef AUDIO_ENABLE
play_note(freq, 0xF); play_note(freq, 0xF);
if (music_sequence_recording) { if (music_sequence_recording) {
music_sequence[music_sequence_count] = freq; music_sequence[music_sequence_count] = freq;
music_sequence_count++; music_sequence_count++;
} }
#endif
} else { } else {
#ifdef AUDIO_ENABLE
stop_note(freq); stop_note(freq);
#endif
} }
if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
@ -161,15 +177,19 @@ void music_on(void) {
void music_off(void) { void music_off(void) {
music_activated = 0; music_activated = 0;
#ifdef AUDIO_ENABLE
stop_all_notes(); stop_all_notes();
#endif
} }
__attribute__ ((weak)) __attribute__ ((weak))
void music_on_user() {} void music_on_user() {}
#ifdef AUDIO_ENABLE
__attribute__ ((weak)) __attribute__ ((weak))
void audio_on_user() {} void audio_on_user() {}
#endif
__attribute__ ((weak)) __attribute__ ((weak))
void music_scale_user() {} void music_scale_user() {}
@ -178,8 +198,10 @@ void matrix_scan_music(void) {
if (music_sequence_playing) { if (music_sequence_playing) {
if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) { if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
music_sequence_timer = timer_read(); music_sequence_timer = timer_read();
#ifdef AUDIO_ENABLE
stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]); stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]);
play_note(music_sequence[music_sequence_position], 0xF); play_note(music_sequence[music_sequence_position], 0xF);
#endif
music_sequence_position = (music_sequence_position + 1) % music_sequence_count; music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
} }
} }

@ -150,10 +150,10 @@ bool process_record_quantum(keyrecord_t *record) {
if (!( if (!(
process_record_kb(keycode, record) && process_record_kb(keycode, record) &&
#ifdef MIDI_ENABLE #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
process_midi(keycode, record) && process_midi(keycode, record) &&
#endif #endif
#ifdef AUDIO_ENABLE #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
process_music(keycode, record) && process_music(keycode, record) &&
#endif #endif
#ifdef TAP_DANCE_ENABLE #ifdef TAP_DANCE_ENABLE

@ -2,7 +2,7 @@
#ifndef QUANTUM_KEYCODES_H #ifndef QUANTUM_KEYCODES_H
#define QUANTUM_KEYCODES_H #define QUANTUM_KEYCODES_H
#ifdef MIDI_ENABLE #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
#ifndef MIDI_TONE_KEYCODE_OCTAVES #ifndef MIDI_TONE_KEYCODE_OCTAVES
#define MIDI_TONE_KEYCODE_OCTAVES 3 #define MIDI_TONE_KEYCODE_OCTAVES 3
#endif #endif
@ -116,6 +116,12 @@ enum quantum_keycodes {
#ifdef MIDI_ENABLE #ifdef MIDI_ENABLE
// Midi // Midi
#ifdef MIDI_BASIC
MI_ON, // send midi notes when music mode is enabled
MI_OFF, // don't send midi notes when music mode is enabled
#endif
#ifdef MIDI_ADVANCED
MIDI_TONE_MIN, MIDI_TONE_MIN,
#if MIDI_TONE_KEYCODE_OCTAVES > 0 #if MIDI_TONE_KEYCODE_OCTAVES > 0
@ -321,7 +327,7 @@ enum quantum_keycodes {
MI_CHD, // previous channel MI_CHD, // previous channel
MI_CHU, // next channel MI_CHU, // next channel
MI_OFF, // all notes off MI_ALLOFF, // all notes off
MI_SUS, // sustain MI_SUS, // sustain
MI_PORT, // portamento MI_PORT, // portamento
@ -332,7 +338,8 @@ enum quantum_keycodes {
MI_MOD, // modulation MI_MOD, // modulation
MI_MODSD, // decrease modulation speed MI_MODSD, // decrease modulation speed
MI_MODSU, // increase modulation speed MI_MODSU, // increase modulation speed
#endif #endif // MIDI_ADVANCED
#endif // MIDI_ENABLE
// Backlight functionality // Backlight functionality
BL_0, BL_0,

@ -159,6 +159,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define NO_ACTION_MACRO //#define NO_ACTION_MACRO
//#define NO_ACTION_FUNCTION //#define NO_ACTION_FUNCTION
/*
* MIDI options
*/
/* enable basic MIDI features:
- MIDI notes can be sent when in Music mode is on
*/
//#define MIDI_BASIC
/* enable advanced MIDI features:
- MIDI notes can be added to the keymap
- Octave shift and transpose
- Virtual sustain, portamento, and modulation wheel
- etc.
*/
//#define MIDI_ADVANCED
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ /* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
//#define MIDI_TONE_KEYCODE_OCTAVES 1 //#define MIDI_TONE_KEYCODE_OCTAVES 1

@ -1104,7 +1104,9 @@ void sysex_callback(MidiDevice * device,
void setup_midi(void) void setup_midi(void)
{ {
#ifdef MIDI_ADVANCED
midi_init(); midi_init();
#endif
midi_device_init(&midi_device); midi_device_init(&midi_device);
midi_device_set_send_func(&midi_device, usb_send_func); midi_device_set_send_func(&midi_device, usb_send_func);
midi_device_set_pre_input_process_func(&midi_device, usb_get_midi); midi_device_set_pre_input_process_func(&midi_device, usb_get_midi);
@ -1180,8 +1182,10 @@ int main(void)
#ifdef MIDI_ENABLE #ifdef MIDI_ENABLE
midi_device_process(&midi_device); midi_device_process(&midi_device);
#ifdef MIDI_ADVANCED
midi_task(); midi_task();
#endif #endif
#endif
#if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE) #if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE)
rgblight_task(); rgblight_task();

Loading…
Cancel
Save