muse working with encoder as control
This commit is contained in:
		
							parent
							
								
									edb4460e64
								
							
						
					
					
						commit
						e0e5efbead
					
				
					 8 changed files with 210 additions and 51 deletions
				
			
		| 
						 | 
				
			
			@ -16,6 +16,7 @@
 | 
			
		|||
 | 
			
		||||
#include "planck.h"
 | 
			
		||||
#include "action_layer.h"
 | 
			
		||||
#include "muse.h"
 | 
			
		||||
 | 
			
		||||
extern keymap_config_t keymap_config;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -267,20 +268,42 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
 | 
			
		|||
  return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void encoder_update(bool direction) {
 | 
			
		||||
  if (direction) {
 | 
			
		||||
    register_code(KC_PGUP);
 | 
			
		||||
    unregister_code(KC_PGUP);
 | 
			
		||||
bool muse_mode = false;
 | 
			
		||||
uint8_t last_muse_note = 0;
 | 
			
		||||
uint16_t muse_counter = 0;
 | 
			
		||||
uint8_t muse_offset = 70;
 | 
			
		||||
uint16_t muse_tempo = 50;
 | 
			
		||||
 | 
			
		||||
void encoder_update(bool clockwise) {
 | 
			
		||||
  if (muse_mode) {
 | 
			
		||||
    if (IS_LAYER_ON(_RAISE)) {
 | 
			
		||||
      if (clockwise) {
 | 
			
		||||
        muse_offset++;
 | 
			
		||||
      } else {
 | 
			
		||||
        muse_offset--;
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      if (clockwise) {
 | 
			
		||||
        muse_tempo+=1;
 | 
			
		||||
      } else {
 | 
			
		||||
        muse_tempo-=1;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  } else {
 | 
			
		||||
    register_code(KC_PGDN);
 | 
			
		||||
    unregister_code(KC_PGDN);
 | 
			
		||||
    if (clockwise) {
 | 
			
		||||
      register_code(KC_PGUP);
 | 
			
		||||
      unregister_code(KC_PGUP);
 | 
			
		||||
    } else {
 | 
			
		||||
      register_code(KC_PGDN);
 | 
			
		||||
      unregister_code(KC_PGDN);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dip_update(uint8_t index, bool value) {
 | 
			
		||||
void dip_update(uint8_t index, bool active) {
 | 
			
		||||
  switch (index) {
 | 
			
		||||
    case 0:
 | 
			
		||||
      if (value) {
 | 
			
		||||
      if (active) {
 | 
			
		||||
        #ifdef AUDIO_ENABLE
 | 
			
		||||
          PLAY_SONG(plover_song);
 | 
			
		||||
        #endif
 | 
			
		||||
| 
						 | 
				
			
			@ -292,5 +315,35 @@ void dip_update(uint8_t index, bool value) {
 | 
			
		|||
        layer_off(_ADJUST);
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    case 1:
 | 
			
		||||
      if (active) {
 | 
			
		||||
        muse_mode = true;
 | 
			
		||||
      } else {
 | 
			
		||||
        muse_mode = false;
 | 
			
		||||
        stop_all_notes();
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void matrix_init_user(void) {
 | 
			
		||||
  palSetPadMode(GPIOB, 5, PAL_MODE_OUTPUT_PUSHPULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void matrix_scan_user(void) {
 | 
			
		||||
  if (muse_mode) {
 | 
			
		||||
    if (muse_counter == 0) {
 | 
			
		||||
      uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
 | 
			
		||||
      if (muse_note != last_muse_note) {
 | 
			
		||||
        stop_note(compute_freq_for_midi_note(last_muse_note));
 | 
			
		||||
        play_note(compute_freq_for_midi_note(muse_note), 0xF);
 | 
			
		||||
        last_muse_note = muse_note;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    if (muse_counter > (muse_tempo / 2)) {
 | 
			
		||||
      palSetPad(GPIOB, 5);
 | 
			
		||||
    } else {
 | 
			
		||||
      palClearPad(GPIOB, 5);
 | 
			
		||||
    }
 | 
			
		||||
    muse_counter = (muse_counter + 1) % muse_tempo;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue