summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build_keyboard.mk1
-rw-r--r--keyboards/satan/keymaps/midi/config.h17
-rw-r--r--keyboards/satan/keymaps/midi/keymap.c4
-rw-r--r--quantum/process_keycode/process_midi.c9
-rw-r--r--quantum/process_keycode/process_music.c22
-rw-r--r--quantum/quantum.c4
-rw-r--r--quantum/quantum_keycodes.h13
-rw-r--r--quantum/template/config.h17
-rw-r--r--tmk_core/protocol/lufa/lufa.c4
9 files changed, 80 insertions, 11 deletions
diff --git a/build_keyboard.mk b/build_keyboard.mk
index 4a6fc0980..eea8d5919 100644
--- a/build_keyboard.mk
+++ b/build_keyboard.mk
@@ -141,6 +141,7 @@ endif
ifeq ($(strip $(MIDI_ENABLE)), yes)
OPT_DEFS += -DMIDI_ENABLE
+ SRC += $(QUANTUM_DIR)/process_keycode/process_music.c
SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c
endif
diff --git a/keyboards/satan/keymaps/midi/config.h b/keyboards/satan/keymaps/midi/config.h
index 0dbdb5cbc..59250b49e 100644
--- a/keyboards/satan/keymaps/midi/config.h
+++ b/keyboards/satan/keymaps/midi/config.h
@@ -3,7 +3,22 @@
#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) */
#define MIDI_TONE_KEYCODE_OCTAVES 2
diff --git a/keyboards/satan/keymaps/midi/keymap.c b/keyboards/satan/keymaps/midi/keymap.c
index 397fe097b..349391c3b 100644
--- a/keyboards/satan/keymaps/midi/keymap.c
+++ b/keyboards/satan/keymaps/midi/keymap.c
@@ -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_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
* ,------------------------------------------------------------------------.
* | 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_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_OFF, _______, _______, _______, _______),
+ _______, _______, _______, MI_ALLOFF, _______, _______, _______, _______),
#endif
}; \ No newline at end of file
diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c
index 5530ea97c..161f04a24 100644
--- a/quantum/process_keycode/process_midi.c
+++ b/quantum/process_keycode/process_midi.c
@@ -1,6 +1,7 @@
-#define MIDI_TONE_KEYCODE_OCTAVES 2
-
#include "process_midi.h"
+
+#if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
+
#include "timer.h"
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);
}
return false;
- case MI_OFF:
+ case MI_ALLOFF:
if (record->event.pressed) {
midi_send_cc(&midi_device, midi_config.channel, 0x7B, 0);
dprintf("midi off\n");
@@ -209,3 +210,5 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
return true;
}
+
+#endif // MIDI_ADVANCED
diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c
index 1e2648bff..ac906b628 100644
--- a/quantum/process_keycode/process_music.c
+++ b/quantum/process_keycode/process_music.c
@@ -17,6 +17,7 @@ static uint16_t music_sequence_interval = 100;
bool process_music(uint16_t keycode, keyrecord_t *record) {
+ #ifdef AUDIO_ENABLE
if (keycode == AU_ON && record->event.pressed) {
audio_on();
return false;
@@ -38,6 +39,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
}
return false;
}
+ #endif // AUDIO_ENABLE
if (keycode == MU_ON && record->event.pressed) {
music_on();
@@ -61,6 +63,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
return false;
}
+ #ifdef AUDIO_ENABLE
if (keycode == MUV_IN && record->event.pressed) {
voice_iterate();
music_scale_user();
@@ -72,11 +75,14 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
music_scale_user();
return false;
}
+ #endif // AUDIO_ENABLE
if (music_activated) {
if (keycode == KC_LCTL && record->event.pressed) { // Start recording
+ #ifdef AUDIO_ENABLE
stop_all_notes();
+ #endif
music_sequence_recording = true;
music_sequence_recorded = 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
+ #ifdef AUDIO_ENABLE
stop_all_notes();
+ #endif
if (music_sequence_recording) { // was recording
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
+ #ifdef AUDIO_ENABLE
stop_all_notes();
+ #endif
music_sequence_recording = false;
music_sequence_playing = true;
music_sequence_position = 0;
@@ -116,6 +126,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
}
#define MUSIC_MODE_GUITAR
+ #ifdef AUDIO_ENABLE
#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));
#elif defined(MUSIC_MODE_GUITAR)
@@ -125,15 +136,20 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
#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));
#endif
+ #endif // AUDIO_ENABLE
if (record->event.pressed) {
+ #ifdef AUDIO_ENABLE
play_note(freq, 0xF);
if (music_sequence_recording) {
music_sequence[music_sequence_count] = freq;
music_sequence_count++;
}
+ #endif
} else {
+ #ifdef AUDIO_ENABLE
stop_note(freq);
+ #endif
}
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) {
music_activated = 0;
+ #ifdef AUDIO_ENABLE
stop_all_notes();
+ #endif
}
__attribute__ ((weak))
void music_on_user() {}
+#ifdef AUDIO_ENABLE
__attribute__ ((weak))
void audio_on_user() {}
+#endif
__attribute__ ((weak))
void music_scale_user() {}
@@ -178,8 +198,10 @@ void matrix_scan_music(void) {
if (music_sequence_playing) {
if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
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)]);
play_note(music_sequence[music_sequence_position], 0xF);
+ #endif
music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
}
}
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 4a6d0355f..83fa87708 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -150,10 +150,10 @@ bool process_record_quantum(keyrecord_t *record) {
if (!(
process_record_kb(keycode, record) &&
- #ifdef MIDI_ENABLE
+ #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
process_midi(keycode, record) &&
#endif
- #ifdef AUDIO_ENABLE
+ #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
process_music(keycode, record) &&
#endif
#ifdef TAP_DANCE_ENABLE
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index 6d1438051..3b82b7208 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -2,7 +2,7 @@
#ifndef QUANTUM_KEYCODES_H
#define QUANTUM_KEYCODES_H
-#ifdef MIDI_ENABLE
+#if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
#ifndef MIDI_TONE_KEYCODE_OCTAVES
#define MIDI_TONE_KEYCODE_OCTAVES 3
#endif
@@ -116,6 +116,12 @@ enum quantum_keycodes {
#ifdef MIDI_ENABLE
// 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,
#if MIDI_TONE_KEYCODE_OCTAVES > 0
@@ -321,7 +327,7 @@ enum quantum_keycodes {
MI_CHD, // previous channel
MI_CHU, // next channel
- MI_OFF, // all notes off
+ MI_ALLOFF, // all notes off
MI_SUS, // sustain
MI_PORT, // portamento
@@ -332,7 +338,8 @@ enum quantum_keycodes {
MI_MOD, // modulation
MI_MODSD, // decrease modulation speed
MI_MODSU, // increase modulation speed
-#endif
+#endif // MIDI_ADVANCED
+#endif // MIDI_ENABLE
// Backlight functionality
BL_0,
diff --git a/quantum/template/config.h b/quantum/template/config.h
index cd6dfa2c6..54db4f242 100644
--- a/quantum/template/config.h
+++ b/quantum/template/config.h
@@ -159,6 +159,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define NO_ACTION_MACRO
//#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) */
//#define MIDI_TONE_KEYCODE_OCTAVES 1
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index bd2498057..651a0f347 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -1104,7 +1104,9 @@ void sysex_callback(MidiDevice * device,
void setup_midi(void)
{
+#ifdef MIDI_ADVANCED
midi_init();
+#endif
midi_device_init(&midi_device);
midi_device_set_send_func(&midi_device, usb_send_func);
midi_device_set_pre_input_process_func(&midi_device, usb_get_midi);
@@ -1180,8 +1182,10 @@ int main(void)
#ifdef MIDI_ENABLE
midi_device_process(&midi_device);
+#ifdef MIDI_ADVANCED
midi_task();
#endif
+#endif
#if defined(RGBLIGHT_ANIMATIONS) & defined(RGBLIGHT_ENABLE)
rgblight_task();