Merge pull request #1112 from newsboytko/newsboytko/midi-keycodes
Flesh out MIDI supportb6_b7_audio 0.5.36
commit
7e37daa2ce
@ -0,0 +1,29 @@ |
||||
#ifndef CONFIG_USER_H |
||||
#define CONFIG_USER_H |
||||
|
||||
#include "../../config.h" |
||||
|
||||
/*
|
||||
* MIDI options |
||||
*/ |
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */ |
||||
//#define MIDI_ENABLE_STRICT 1
|
||||
|
||||
/* 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) */ |
||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||
|
||||
#endif |
@ -0,0 +1,29 @@ |
||||
#ifndef CONFIG_USER_H |
||||
#define CONFIG_USER_H |
||||
|
||||
#include "../../config.h" |
||||
|
||||
/*
|
||||
* MIDI options |
||||
*/ |
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */ |
||||
//#define MIDI_ENABLE_STRICT 1
|
||||
|
||||
/* 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) */ |
||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||
|
||||
#endif |
@ -0,0 +1,29 @@ |
||||
#ifndef CONFIG_USER_H |
||||
#define CONFIG_USER_H |
||||
|
||||
#include "../../config.h" |
||||
|
||||
/*
|
||||
* MIDI options |
||||
*/ |
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */ |
||||
//#define MIDI_ENABLE_STRICT 1
|
||||
|
||||
/* 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) */ |
||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||
|
||||
#endif |
@ -0,0 +1,29 @@ |
||||
#ifndef CONFIG_USER_H |
||||
#define CONFIG_USER_H |
||||
|
||||
#include "../../config.h" |
||||
|
||||
/*
|
||||
* MIDI options |
||||
*/ |
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */ |
||||
//#define MIDI_ENABLE_STRICT 1
|
||||
|
||||
/* 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) */ |
||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||
|
||||
#endif |
@ -0,0 +1,29 @@ |
||||
#ifndef CONFIG_USER_H |
||||
#define CONFIG_USER_H |
||||
|
||||
#include "../../config.h" |
||||
|
||||
/*
|
||||
* MIDI options |
||||
*/ |
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */ |
||||
//#define MIDI_ENABLE_STRICT 1
|
||||
|
||||
/* 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) */ |
||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||
|
||||
#endif |
@ -0,0 +1,29 @@ |
||||
#ifndef CONFIG_USER_H |
||||
#define CONFIG_USER_H |
||||
|
||||
#include "../../config.h" |
||||
|
||||
/*
|
||||
* MIDI options |
||||
*/ |
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */ |
||||
//#define MIDI_ENABLE_STRICT 1
|
||||
|
||||
/* 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) */ |
||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||
|
||||
#endif |
@ -0,0 +1,29 @@ |
||||
#ifndef CONFIG_USER_H |
||||
#define CONFIG_USER_H |
||||
|
||||
#include "../../config.h" |
||||
|
||||
/*
|
||||
* MIDI options |
||||
*/ |
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */ |
||||
//#define MIDI_ENABLE_STRICT 1
|
||||
|
||||
/* 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) */ |
||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||
|
||||
#endif |
@ -0,0 +1,29 @@ |
||||
#ifndef CONFIG_USER_H |
||||
#define CONFIG_USER_H |
||||
|
||||
#include "../../config.h" |
||||
|
||||
/*
|
||||
* MIDI options |
||||
*/ |
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */ |
||||
//#define MIDI_ENABLE_STRICT 1
|
||||
|
||||
/* 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) */ |
||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||
|
||||
#endif |
@ -0,0 +1,29 @@ |
||||
#ifndef CONFIG_USER_H |
||||
#define CONFIG_USER_H |
||||
|
||||
#include "../../config.h" |
||||
|
||||
/*
|
||||
* MIDI options |
||||
*/ |
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */ |
||||
//#define MIDI_ENABLE_STRICT 1
|
||||
|
||||
/* 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) */ |
||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||
|
||||
#endif |
@ -0,0 +1,29 @@ |
||||
#ifndef CONFIG_USER_H |
||||
#define CONFIG_USER_H |
||||
|
||||
#include "../../config.h" |
||||
|
||||
/*
|
||||
* MIDI options |
||||
*/ |
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */ |
||||
//#define MIDI_ENABLE_STRICT 1
|
||||
|
||||
/* 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) */ |
||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||
|
||||
#endif |
@ -0,0 +1,29 @@ |
||||
#ifndef CONFIG_USER_H |
||||
#define CONFIG_USER_H |
||||
|
||||
#include "../../config.h" |
||||
|
||||
/*
|
||||
* MIDI options |
||||
*/ |
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */ |
||||
//#define MIDI_ENABLE_STRICT 1
|
||||
|
||||
/* 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) */ |
||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||
|
||||
#endif |
@ -0,0 +1,29 @@ |
||||
#ifndef CONFIG_USER_H |
||||
#define CONFIG_USER_H |
||||
|
||||
#include "../../config.h" |
||||
|
||||
/*
|
||||
* MIDI options |
||||
*/ |
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */ |
||||
//#define MIDI_ENABLE_STRICT 1
|
||||
|
||||
/* 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) */ |
||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||
|
||||
#endif |
@ -0,0 +1,21 @@ |
||||
# Build Options
|
||||
# change to "no" to disable the options, or define them in the Makefile in
|
||||
# the appropriate keymap folder that will get included automatically
|
||||
#
|
||||
BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
|
||||
MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
|
||||
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
|
||||
CONSOLE_ENABLE = no # Console for debug(+400)
|
||||
COMMAND_ENABLE = yes # Commands for debug and configuration
|
||||
NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
|
||||
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
|
||||
MIDI_ENABLE = yes # MIDI support (+2400 to 4200, depending on config)
|
||||
AUDIO_ENABLE = no # Audio output on port C6
|
||||
UNICODE_ENABLE = no # Unicode
|
||||
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
|
||||
RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. Do not enable this with audio at the same time.
|
||||
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
|
||||
|
||||
ifndef QUANTUM_DIR |
||||
include ../../../../Makefile
|
||||
endif |
@ -0,0 +1,29 @@ |
||||
#ifndef CONFIG_USER_H |
||||
#define CONFIG_USER_H |
||||
|
||||
#include "../../config.h" |
||||
|
||||
/*
|
||||
* MIDI options |
||||
*/ |
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */ |
||||
#define MIDI_ENABLE_STRICT 1 |
||||
|
||||
/* 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) */ |
||||
#define MIDI_TONE_KEYCODE_OCTAVES 2 |
||||
|
||||
#endif |
@ -0,0 +1,77 @@ |
||||
#include "satan.h" |
||||
|
||||
// Each layer gets a name for readability, which is then used in the keymap matrix below.
|
||||
// The underscores don't mean anything - you can have a layer called STUFF or any other name.
|
||||
// Layer names don't all need to be of the same length, obviously, and you can also skip them
|
||||
// entirely and just use numbers.
|
||||
#define _BL 0 |
||||
#define _ML 1 |
||||
|
||||
// readability
|
||||
#define _______ KC_TRNS |
||||
#define XXXXXXX KC_NO |
||||
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { |
||||
/* Keymap _BL: (Base Layer) Default Layer
|
||||
* ,-----------------------------------------------------------. |
||||
* |Esc | 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp | |
||||
* |-----------------------------------------------------------| |
||||
* |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \ | |
||||
* |-----------------------------------------------------------| |
||||
* |CAPS | A| S| D| F| G| H| J| K| L| ;| '|Return | |
||||
* |-----------------------------------------------------------| |
||||
* |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift | |
||||
* |-----------------------------------------------------------| |
||||
* |Ctrl|Gui |Alt | Space |Alt |Gui |Midi|Ctrl | |
||||
* `-----------------------------------------------------------' |
||||
*/ |
||||
[_BL] = KEYMAP_ANSI( |
||||
KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, \
|
||||
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC,KC_BSLS, \
|
||||
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT, KC_ENT, \
|
||||
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), |
||||
|
||||
#if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) |
||||
/* Keymap _ML: MIDI Layer (Advanced)
|
||||
* ,------------------------------------------------------------------------. |
||||
* | Exit | | | | | | | | | | | | | | |
||||
* |------------------------------------------------------------------------| |
||||
* | Ch+ | | C# | D# | | F# | G# | A# | | C# | D# | | | | |
||||
* |------------------------------------------------------------------------| |
||||
* | Mod | C | D | E | F | G | A | B | C | D | E | F | | |
||||
* |------------------------------------------------------------------------| |
||||
* | Sustain |Oct-|Oct+|Mod-|Mod+| | | |Tns-|Tns+|Tns0| Sustain | |
||||
* |------------------------------------------------------------------------| |
||||
* | | | | All notes off | | | | | |
||||
* `------------------------------------------------------------------------' |
||||
*/ |
||||
[_ML] = KEYMAP_ANSI( |
||||
TG(_ML), MI_VEL_1, MI_VEL_2, MI_VEL_3, MI_VEL_4, MI_VEL_5, MI_VEL_6, MI_VEL_7, MI_VEL_8, MI_VEL_9, MI_VEL_10, 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_SUS, MI_OCTD, MI_OCTU, MI_MODSD, MI_MODSU, XXXXXXX, XXXXXXX, XXXXXXX, MI_TRNSD, MI_TRNSU, MI_TRNS_0, MI_SUS, \
|
||||
_______, _______, _______, MI_ALLOFF, _______, _______, _______, _______), |
||||
#elif defined(MIDI_ENABLE) && defined(MIDI_BASIC) |
||||
/* Keymap _ML: MIDI Layer (Advanced)
|
||||
* ,------------------------------------------------------------------------. |
||||
* | Exit | | | | | | | | | | | | | | |
||||
* |------------------------------------------------------------------------| |
||||
* | | | | | | | | | | | | | | | |
||||
* |------------------------------------------------------------------------| |
||||
* | | | | | | | | | | | | | | |
||||
* |------------------------------------------------------------------------| |
||||
* | |MuOn|MuOf|MiOn|MiOf| | | | | | | | |
||||
* |------------------------------------------------------------------------| |
||||
* | | | | | | | | | |
||||
* `------------------------------------------------------------------------' |
||||
*/ |
||||
|
||||
[_ML] = KEYMAP_ANSI( |
||||
TG(_ML), _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
|
||||
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
|
||||
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
|
||||
_______, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______, _______, _______, \
|
||||
_______, _______, _______, _______, _______, _______, _______, _______), |
||||
#endif |
||||
}; |
@ -0,0 +1 @@ |
||||
# Satan GH60 layout demonstrating MIDI key mapping |
@ -0,0 +1,29 @@ |
||||
#ifndef CONFIG_USER_H |
||||
#define CONFIG_USER_H |
||||
|
||||
#include "../../config.h" |
||||
|
||||
/*
|
||||
* MIDI options |
||||
*/ |
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */ |
||||
//#define MIDI_ENABLE_STRICT 1
|
||||
|
||||
/* 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) */ |
||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||
|
||||
#endif |
@ -0,0 +1,62 @@ |
||||
#include "audio.h" |
||||
#include "process_audio.h" |
||||
|
||||
static float compute_freq_for_midi_note(uint8_t note) |
||||
{ |
||||
// https://en.wikipedia.org/wiki/MIDI_tuning_standard
|
||||
return pow(2.0, (note - 69) / 12.0) * 440.0f; |
||||
} |
||||
|
||||
bool process_audio(uint16_t keycode, keyrecord_t *record) { |
||||
|
||||
if (keycode == AU_ON && record->event.pressed) { |
||||
audio_on(); |
||||
return false; |
||||
} |
||||
|
||||
if (keycode == AU_OFF && record->event.pressed) { |
||||
audio_off(); |
||||
return false; |
||||
} |
||||
|
||||
if (keycode == AU_TOG && record->event.pressed) { |
||||
if (is_audio_on()) |
||||
{ |
||||
audio_off(); |
||||
} |
||||
else |
||||
{ |
||||
audio_on(); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
if (keycode == MUV_IN && record->event.pressed) { |
||||
voice_iterate(); |
||||
music_scale_user(); |
||||
return false; |
||||
} |
||||
|
||||
if (keycode == MUV_DE && record->event.pressed) { |
||||
voice_deiterate(); |
||||
music_scale_user(); |
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
void process_audio_noteon(uint8_t note) { |
||||
play_note(compute_freq_for_midi_note(note), 0xF); |
||||
} |
||||
|
||||
void process_audio_noteoff(uint8_t note) { |
||||
stop_note(compute_freq_for_midi_note(note)); |
||||
} |
||||
|
||||
void process_audio_all_notes_off(void) { |
||||
stop_all_notes(); |
||||
} |
||||
|
||||
__attribute__ ((weak)) |
||||
void audio_on_user() {} |
@ -0,0 +1,11 @@ |
||||
#ifndef PROCESS_AUDIO_H |
||||
#define PROCESS_AUDIO_H |
||||
|
||||
bool process_audio(uint16_t keycode, keyrecord_t *record); |
||||
void process_audio_noteon(uint8_t note); |
||||
void process_audio_noteoff(uint8_t note); |
||||
void process_audio_all_notes_off(void); |
||||
|
||||
void audio_on_user(void); |
||||
|
||||
#endif |
@ -1,68 +1,238 @@ |
||||
#include "process_midi.h" |
||||
|
||||
bool midi_activated = false; |
||||
uint8_t midi_starting_note = 0x0C; |
||||
int midi_offset = 7; |
||||
#ifdef MIDI_ENABLE |
||||
#include "midi.h" |
||||
|
||||
bool process_midi(uint16_t keycode, keyrecord_t *record) { |
||||
if (keycode == MI_ON && record->event.pressed) { |
||||
midi_activated = true; |
||||
#ifdef AUDIO_ENABLE |
||||
music_scale_user(); |
||||
#endif |
||||
return false; |
||||
#ifdef MIDI_BASIC |
||||
|
||||
void process_midi_basic_noteon(uint8_t note)
|
||||
{ |
||||
midi_send_noteon(&midi_device, 0, note, 128); |
||||
} |
||||
|
||||
if (keycode == MI_OFF && record->event.pressed) { |
||||
midi_activated = false; |
||||
void process_midi_basic_noteoff(uint8_t note) |
||||
{ |
||||
midi_send_noteoff(&midi_device, 0, note, 0); |
||||
} |
||||
|
||||
void process_midi_all_notes_off(void) |
||||
{ |
||||
midi_send_cc(&midi_device, 0, 0x7B, 0); |
||||
return false; |
||||
} |
||||
|
||||
if (midi_activated) { |
||||
if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) { |
||||
#endif // MIDI_BASIC
|
||||
|
||||
#ifdef MIDI_ADVANCED |
||||
|
||||
#include "timer.h" |
||||
|
||||
static uint8_t tone_status[MIDI_TONE_COUNT]; |
||||
|
||||
static uint8_t midi_modulation; |
||||
static int8_t midi_modulation_step; |
||||
static uint16_t midi_modulation_timer; |
||||
|
||||
inline uint8_t compute_velocity(uint8_t setting) |
||||
{ |
||||
return (setting + 1) * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN + 1)); |
||||
} |
||||
|
||||
void midi_init(void) |
||||
{ |
||||
midi_config.octave = MI_OCT_2 - MIDI_OCTAVE_MIN; |
||||
midi_config.transpose = 0; |
||||
midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN); |
||||
midi_config.channel = 0; |
||||
midi_config.modulation_interval = 8; |
||||
|
||||
for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++) |
||||
{ |
||||
tone_status[i] = MIDI_INVALID_NOTE; |
||||
} |
||||
|
||||
midi_modulation = 0; |
||||
midi_modulation_step = 0; |
||||
midi_modulation_timer = 0; |
||||
} |
||||
|
||||
void midi_task(void) |
||||
{ |
||||
if (timer_elapsed(midi_modulation_timer) < midi_config.modulation_interval) |
||||
return; |
||||
midi_modulation_timer = timer_read(); |
||||
|
||||
if (midi_modulation_step != 0) |
||||
{ |
||||
dprintf("midi modulation %d\n", midi_modulation); |
||||
midi_send_cc(&midi_device, midi_config.channel, 0x1, midi_modulation); |
||||
|
||||
if (midi_modulation_step < 0 && midi_modulation < -midi_modulation_step) { |
||||
midi_modulation = 0; |
||||
midi_modulation_step = 0; |
||||
return; |
||||
} |
||||
|
||||
midi_modulation += midi_modulation_step; |
||||
|
||||
if (midi_modulation > 127) |
||||
midi_modulation = 127; |
||||
} |
||||
} |
||||
|
||||
uint8_t midi_compute_note(uint16_t keycode) |
||||
{ |
||||
return 12 * midi_config.octave + (keycode - MIDI_TONE_MIN) + midi_config.transpose; |
||||
} |
||||
|
||||
bool process_midi(uint16_t keycode, keyrecord_t *record) |
||||
{ |
||||
switch (keycode) { |
||||
case MIDI_TONE_MIN ... MIDI_TONE_MAX: |
||||
{ |
||||
uint8_t channel = midi_config.channel; |
||||
uint8_t tone = keycode - MIDI_TONE_MIN; |
||||
uint8_t velocity = compute_velocity(midi_config.velocity); |
||||
if (record->event.pressed) { |
||||
midi_starting_note++; // Change key
|
||||
midi_send_cc(&midi_device, 0, 0x7B, 0); |
||||
uint8_t note = midi_compute_note(keycode); |
||||
midi_send_noteon(&midi_device, channel, note, velocity); |
||||
dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity); |
||||
tone_status[tone] = note; |
||||
} |
||||
else { |
||||
uint8_t note = tone_status[tone]; |
||||
if (note != MIDI_INVALID_NOTE) |
||||
{ |
||||
midi_send_noteoff(&midi_device, channel, note, velocity); |
||||
dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity); |
||||
} |
||||
tone_status[tone] = MIDI_INVALID_NOTE; |
||||
} |
||||
return false; |
||||
} |
||||
if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) { |
||||
case MIDI_OCTAVE_MIN ... MIDI_OCTAVE_MAX: |
||||
if (record->event.pressed) { |
||||
midi_starting_note--; // Change key
|
||||
midi_send_cc(&midi_device, 0, 0x7B, 0); |
||||
midi_config.octave = keycode - MIDI_OCTAVE_MIN; |
||||
dprintf("midi octave %d\n", midi_config.octave); |
||||
} |
||||
return false; |
||||
case MI_OCTD: |
||||
if (record->event.pressed && midi_config.octave > 0) { |
||||
midi_config.octave--; |
||||
dprintf("midi octave %d\n", midi_config.octave); |
||||
} |
||||
if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) { |
||||
midi_offset++; // Change scale
|
||||
midi_send_cc(&midi_device, 0, 0x7B, 0); |
||||
return false; |
||||
case MI_OCTU: |
||||
if (record->event.pressed && midi_config.octave < (MIDI_OCTAVE_MAX - MIDI_OCTAVE_MIN)) { |
||||
midi_config.octave++; |
||||
dprintf("midi octave %d\n", midi_config.octave); |
||||
} |
||||
if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) { |
||||
midi_offset--; // Change scale
|
||||
midi_send_cc(&midi_device, 0, 0x7B, 0); |
||||
return false; |
||||
case MIDI_TRANSPOSE_MIN ... MIDI_TRANSPOSE_MAX: |
||||
if (record->event.pressed) { |
||||
midi_config.transpose = keycode - MI_TRNS_0; |
||||
dprintf("midi transpose %d\n", midi_config.transpose); |
||||
} |
||||
// basic
|
||||
// uint8_t note = (midi_starting_note + SCALE[record->event.key.col + midi_offset])+12*(MATRIX_ROWS - record->event.key.row);
|
||||
// advanced
|
||||
// uint8_t note = (midi_starting_note + record->event.key.col + midi_offset)+12*(MATRIX_ROWS - record->event.key.row);
|
||||
// guitar
|
||||
uint8_t note = (midi_starting_note + record->event.key.col + midi_offset)+5*(MATRIX_ROWS - record->event.key.row); |
||||
// violin
|
||||
// uint8_t note = (midi_starting_note + record->event.key.col + midi_offset)+7*(MATRIX_ROWS - record->event.key.row);
|
||||
|
||||
return false; |
||||
case MI_TRNSD: |
||||
if (record->event.pressed && midi_config.transpose > (MIDI_TRANSPOSE_MIN - MI_TRNS_0)) { |
||||
midi_config.transpose--; |
||||
dprintf("midi transpose %d\n", midi_config.transpose); |
||||
} |
||||
return false; |
||||
case MI_TRNSU: |
||||
if (record->event.pressed && midi_config.transpose < (MIDI_TRANSPOSE_MAX - MI_TRNS_0)) { |
||||
const bool positive = midi_config.transpose > 0; |
||||
midi_config.transpose++; |
||||
if (positive && midi_config.transpose < 0) |
||||
midi_config.transpose--; |
||||
dprintf("midi transpose %d\n", midi_config.transpose); |
||||
} |
||||
return false; |
||||
case MIDI_VELOCITY_MIN ... MIDI_VELOCITY_MAX: |
||||
if (record->event.pressed) { |
||||
// midi_send_noteon(&midi_device, record->event.key.row, midi_starting_note + SCALE[record->event.key.col], 127);
|
||||
midi_send_noteon(&midi_device, 0, note, 127); |
||||
} else { |
||||
// midi_send_noteoff(&midi_device, record->event.key.row, midi_starting_note + SCALE[record->event.key.col], 127);
|
||||
midi_send_noteoff(&midi_device, 0, note, 127); |
||||
midi_config.velocity = keycode - MIDI_VELOCITY_MIN; |
||||
dprintf("midi velocity %d\n", midi_config.velocity); |
||||
} |
||||
return false; |
||||
case MI_VELD: |
||||
if (record->event.pressed && midi_config.velocity > 0) { |
||||
midi_config.velocity--; |
||||
dprintf("midi velocity %d\n", midi_config.velocity); |
||||
} |
||||
return false; |
||||
case MI_VELU: |
||||
if (record->event.pressed) { |
||||
midi_config.velocity++; |
||||
dprintf("midi velocity %d\n", midi_config.velocity); |
||||
} |
||||
|
||||
if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
|
||||
return false; |
||||
case MIDI_CHANNEL_MIN ... MIDI_CHANNEL_MAX: |
||||
if (record->event.pressed) { |
||||
midi_config.channel = keycode - MIDI_CHANNEL_MIN; |
||||
dprintf("midi channel %d\n", midi_config.channel); |
||||
} |
||||
return false; |
||||
case MI_CHD: |
||||
if (record->event.pressed) { |
||||
midi_config.channel--; |
||||
dprintf("midi channel %d\n", midi_config.channel); |
||||
} |
||||
return false; |
||||
case MI_CHU: |
||||
if (record->event.pressed) { |
||||
midi_config.channel++; |
||||
dprintf("midi channel %d\n", midi_config.channel); |
||||
} |
||||
return false; |
||||
case MI_ALLOFF: |
||||
if (record->event.pressed) { |
||||
midi_send_cc(&midi_device, midi_config.channel, 0x7B, 0); |
||||
dprintf("midi all notes off\n"); |
||||
} |
||||
return false; |
||||
case MI_SUS: |
||||
midi_send_cc(&midi_device, midi_config.channel, 0x40, record->event.pressed ? 127 : 0); |
||||
dprintf("midi sustain %d\n", record->event.pressed); |
||||
return false; |
||||
case MI_PORT: |
||||
midi_send_cc(&midi_device, midi_config.channel, 0x41, record->event.pressed ? 127 : 0); |
||||
dprintf("midi portamento %d\n", record->event.pressed); |
||||
return false; |
||||
case MI_SOST: |
||||
midi_send_cc(&midi_device, midi_config.channel, 0x42, record->event.pressed ? 127 : 0); |
||||
dprintf("midi sostenuto %d\n", record->event.pressed); |
||||
return false; |
||||
case MI_SOFT: |
||||
midi_send_cc(&midi_device, midi_config.channel, 0x43, record->event.pressed ? 127 : 0); |
||||
dprintf("midi soft %d\n", record->event.pressed); |
||||
return false; |
||||
case MI_LEG: |
||||
midi_send_cc(&midi_device, midi_config.channel, 0x43, record->event.pressed ? 127 : 0); |
||||
dprintf("midi legato %d\n", record->event.pressed); |
||||
return false; |
||||
case MI_MOD: |
||||
midi_modulation_step = record->event.pressed ? 1 : -1; |
||||
return false; |
||||
case MI_MODSD: |
||||
if (record->event.pressed) { |
||||
midi_config.modulation_interval++; |
||||
// prevent overflow
|
||||
if (midi_config.modulation_interval == 0) |
||||
midi_config.modulation_interval--; |
||||
dprintf("midi modulation interval %d\n", midi_config.modulation_interval); |
||||
} |
||||
return false; |
||||
case MI_MODSU: |
||||
if (record->event.pressed && midi_config.modulation_interval > 0) { |
||||
midi_config.modulation_interval--; |
||||
dprintf("midi modulation interval %d\n", midi_config.modulation_interval); |
||||
} |
||||
return false; |
||||
}; |
||||
|
||||
return true; |
||||
} |
||||
|
||||
#endif // MIDI_ADVANCED
|
||||
|
||||
#endif // MIDI_ENABLE
|
||||
|
Loading…
Reference in new issue