void obs_source_output_audio(obs_source_t source, const struct source_audio *audio) { uint32_t flags = obs_source_get_output_flags(source); size_t blocksize = audio_output_blocksize(obs->audio.audio); struct filtered_audio *output; process_audio(source, audio); pthread_mutex_lock(&source->filter_mutex); output = filter_async_audio(source, &source->audio_data); if (output) { pthread_mutex_lock(&source->audio_mutex); /* wait for video to start before outputting any audio so we * have a base for sync */ if (source->timing_set || (flags & SOURCE_ASYNC_VIDEO) == 0) { struct audio_data data; data.data = output->data; data.frames = output->frames; data.timestamp = output->timestamp; source_output_audio_line(source, &data); } pthread_mutex_unlock(&source->audio_mutex); } pthread_mutex_unlock(&source->filter_mutex); }
int main(int argc, char **argv) { if(parse_options(argc,argv)) { usage(); return 1; } if (return_only) { return 0; } if (version) { std::cout << "Shenidam Version : shenidam-"<< SHENIDAM_VERSION << std::endl; #ifdef SHENIDAM_FFT_THREADED std::cout << "Compiled with threading support for FFTW." << std::endl; #endif #ifdef SHENIDAM_PARALLEL_OMP std::cout << "Compiled with OpenMP support." << std::endl; #endif return 0; } bool has_output = test || send_messages || default_output || out_tracks.size() || can_open_mode; bool has_input = test || in_tracks.size() || can_open_mode; if (quiet && verbose) { verbose = false; } if (!base_set) { fprintf(stderr,"ERROR: A base file is required.\n"); usage(); return 1; } if (!has_output) { fprintf(stderr,"ERROR: No output. One of [-o, -d, -t, -m, -c] is required.\n"); usage(); return 1; } if (!has_input) { fprintf(stderr,"ERROR: No input. One of [-t, -i, -c] is required.\n"); usage(); return 1; } if (test) { return do_test(); } else if (can_open_mode) { return file_info(); } else { return process_audio(); } }
// Audio thread void Scheduler::audio_thread_fn() { try { audio = ALSA<int16_t>::shared(file->audio().channels, file->audio().rate); } catch (std::exception& e) { std::cerr << e.what() << std::endl; audio = Null<int16_t>::shared(file->audio().channels, file->audio().rate); } AlignedBuffer<int16_t> audio_buffer(AVCODEC_MAX_AUDIO_FRAME_SIZE); while (audio_thread_active && aud_pkt_queue.alive()) { if (is_paused) { audio->pause(); while (is_paused) sync_sleep(0.01); audio->unpause(); } avlock.lock(); if (aud_pkt_queue.size() > 0) { auto pkt = aud_pkt_queue.pull(); avlock.unlock(); process_audio(pkt.get(), audio_buffer); } else { avlock.unlock(); // Having some race conditions, quickfix it for now... aud_pkt_queue.wait(); //sync_sleep(0.01); //aud_pkt_queue.signal(); } } audio_thread_active = false; }
JNIEXPORT jboolean JNICALL Java_gnu_javax_sound_sampled_gstreamer_io_GstAudioFileReaderNativePeer_gstreamer_1get_1audio_1format_1file (JNIEnv *env, jclass clazz __attribute__ ((unused)), jobject header) { /* source file */ const char *file = NULL; /* GStreamer elements */ GstElement *source = NULL; jboolean result = JNI_FALSE; /* java fields */ jstring _file = NULL; _file = (*env)->GetObjectField(env, header, fileFID); file = JCL_jstring_to_cstring (env, _file); if (file == NULL) { return JNI_FALSE; } gst_init (NULL, NULL); /* create the source element, will be used to read the file */ source = gst_element_factory_make ("filesrc", "source"); if (source == NULL) { JCL_free_cstring (env, _file, file); return JNI_FALSE; } /* set the file name */ g_object_set (G_OBJECT (source), "location", file, NULL); result = process_audio (source, env, header); /* free stuff */ JCL_free_cstring (env, _file, file); return result; }
void obs_source_output_audio(obs_source_t source, const struct source_audio *audio) { uint32_t flags = obs_source_get_output_flags(source); size_t blocksize = audio_output_blocksize(obs->audio.audio); struct filtered_audio *output; process_audio(source, audio); pthread_mutex_lock(&source->filter_mutex); output = filter_async_audio(source, &source->audio_data); if (output) { pthread_mutex_lock(&source->audio_mutex); /* wait for video to start before outputting any audio so we * have a base for sync */ if (!source->timing_set && (flags & SOURCE_ASYNC_VIDEO) != 0) { struct audiobuf newbuf; size_t audio_size = blocksize * output->frames; newbuf.data = bmalloc(audio_size); newbuf.frames = output->frames; newbuf.timestamp = output->timestamp; memcpy(newbuf.data, output->data, audio_size); da_push_back(source->audio_wait_buffer, &newbuf); } else { struct audio_data data; data.data = output->data; data.frames = output->frames; data.timestamp = output->timestamp; source_output_audio_line(source, &data); } pthread_mutex_unlock(&source->audio_mutex); } pthread_mutex_unlock(&source->filter_mutex); }
void obs_source_output_audio(obs_source_t source, const struct source_audio *audio) { uint32_t flags; struct filtered_audio *output; if (!source || !audio) return; flags = source->info.output_flags; process_audio(source, audio); pthread_mutex_lock(&source->filter_mutex); output = filter_async_audio(source, &source->audio_data); if (output) { bool async = (flags & OBS_SOURCE_ASYNC) != 0; pthread_mutex_lock(&source->audio_mutex); /* wait for video to start before outputting any audio so we * have a base for sync */ if (source->timing_set || !async) { struct audio_data data; for (int i = 0; i < MAX_AV_PLANES; i++) data.data[i] = output->data[i]; data.frames = output->frames; data.timestamp = output->timestamp; source_output_audio_line(source, &data); } pthread_mutex_unlock(&source->audio_mutex); } pthread_mutex_unlock(&source->filter_mutex); }
JNIEXPORT jboolean JNICALL Java_gnu_javax_sound_sampled_gstreamer_io_GstAudioFileReaderNativePeer_gstreamer_1get_1audio_1format_1stream (JNIEnv *env, jclass clazz __attribute__ ((unused)), jobject header, jobject pointer) { GstInputStream *istream = NULL; GstElement *source = NULL; gboolean result = JNI_FALSE; if (header == NULL) return JNI_FALSE; if (pointer == NULL) return JNI_FALSE; gst_init (NULL, NULL); istream = (GstInputStream *) get_object_from_pointer (env, pointer, pointerDataID); if (istream == NULL) return JNI_FALSE; /* init gstreamer */ gst_init (NULL, NULL); /* SOURCE */ source = gst_element_factory_make ("classpathsrc", "source"); if (source == NULL) { g_warning ("unable to create a source"); return JNI_FALSE; } g_object_set (G_OBJECT (source), GST_CLASSPATH_SRC_ISTREAM, istream, NULL); result = process_audio (source, env, header); return result; }
bool process_record_quantum(keyrecord_t *record) { /* This gets the keycode from the key pressed */ keypos_t key = record->event.key; uint16_t keycode; #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) /* TODO: Use store_or_get_action() or a similar function. */ if (!disable_action_cache) { uint8_t layer; if (record->event.pressed) { layer = layer_switch_get_layer(key); update_source_layers_cache(key, layer); } else { layer = read_source_layers_cache(key); } keycode = keymap_key_to_keycode(layer, key); } else #endif keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key); // This is how you use actions here // if (keycode == KC_LEAD) { // action_t action; // action.code = ACTION_DEFAULT_LAYER_SET(0); // process_action(record, action); // return false; // } #ifdef TAP_DANCE_ENABLE preprocess_tap_dance(keycode, record); #endif if (!( #if defined(KEY_LOCK_ENABLE) // Must run first to be able to mask key_up events. process_key_lock(&keycode, record) && #endif #if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY) process_clicky(keycode, record) && #endif //AUDIO_CLICKY process_record_kb(keycode, record) && #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_KEYPRESSES) process_rgb_matrix(keycode, record) && #endif #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) process_midi(keycode, record) && #endif #ifdef AUDIO_ENABLE process_audio(keycode, record) && #endif #ifdef STENO_ENABLE process_steno(keycode, record) && #endif #if ( defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE) process_music(keycode, record) && #endif #ifdef TAP_DANCE_ENABLE process_tap_dance(keycode, record) && #endif #ifdef LEADER_ENABLE process_leader(keycode, record) && #endif #ifdef COMBO_ENABLE process_combo(keycode, record) && #endif #ifdef UNICODE_ENABLE process_unicode(keycode, record) && #endif #ifdef UCIS_ENABLE process_ucis(keycode, record) && #endif #ifdef PRINTING_ENABLE process_printer(keycode, record) && #endif #ifdef AUTO_SHIFT_ENABLE process_auto_shift(keycode, record) && #endif #ifdef UNICODEMAP_ENABLE process_unicode_map(keycode, record) && #endif #ifdef TERMINAL_ENABLE process_terminal(keycode, record) && #endif true)) { return false; } // Shift / paren setup switch(keycode) { case RESET: if (record->event.pressed) { reset_keyboard(); } return false; case DEBUG: if (record->event.pressed) { debug_enable = true; print("DEBUG: enabled.\n"); } return false; #ifdef FAUXCLICKY_ENABLE case FC_TOG: if (record->event.pressed) { FAUXCLICKY_TOGGLE; } return false; case FC_ON: if (record->event.pressed) { FAUXCLICKY_ON; } return false; case FC_OFF: if (record->event.pressed) { FAUXCLICKY_OFF; } return false; #endif #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) case RGB_TOG: // Split keyboards need to trigger on key-up for edge-case issue #ifndef SPLIT_KEYBOARD if (record->event.pressed) { #else if (!record->event.pressed) { #endif rgblight_toggle(); #ifdef SPLIT_KEYBOARD RGB_DIRTY = true; #endif } return false; case RGB_MODE_FORWARD: if (record->event.pressed) { uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT)); if(shifted) { rgblight_step_reverse(); } else { rgblight_step(); } #ifdef SPLIT_KEYBOARD RGB_DIRTY = true; #endif } return false; case RGB_MODE_REVERSE: if (record->event.pressed) { uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT)); if(shifted) { rgblight_step(); } else { rgblight_step_reverse(); } #ifdef SPLIT_KEYBOARD RGB_DIRTY = true; #endif } return false; case RGB_HUI: // Split keyboards need to trigger on key-up for edge-case issue #ifndef SPLIT_KEYBOARD if (record->event.pressed) { #else if (!record->event.pressed) { #endif rgblight_increase_hue(); #ifdef SPLIT_KEYBOARD RGB_DIRTY = true; #endif } return false; case RGB_HUD: // Split keyboards need to trigger on key-up for edge-case issue #ifndef SPLIT_KEYBOARD if (record->event.pressed) { #else if (!record->event.pressed) { #endif rgblight_decrease_hue(); #ifdef SPLIT_KEYBOARD RGB_DIRTY = true; #endif } return false; case RGB_SAI: // Split keyboards need to trigger on key-up for edge-case issue #ifndef SPLIT_KEYBOARD if (record->event.pressed) { #else if (!record->event.pressed) { #endif rgblight_increase_sat(); #ifdef SPLIT_KEYBOARD RGB_DIRTY = true; #endif } return false; case RGB_SAD: // Split keyboards need to trigger on key-up for edge-case issue #ifndef SPLIT_KEYBOARD if (record->event.pressed) { #else if (!record->event.pressed) { #endif rgblight_decrease_sat(); #ifdef SPLIT_KEYBOARD RGB_DIRTY = true; #endif } return false; case RGB_VAI: // Split keyboards need to trigger on key-up for edge-case issue #ifndef SPLIT_KEYBOARD if (record->event.pressed) { #else if (!record->event.pressed) { #endif rgblight_increase_val(); #ifdef SPLIT_KEYBOARD RGB_DIRTY = true; #endif } return false; case RGB_VAD: // Split keyboards need to trigger on key-up for edge-case issue #ifndef SPLIT_KEYBOARD if (record->event.pressed) { #else if (!record->event.pressed) { #endif rgblight_decrease_val(); #ifdef SPLIT_KEYBOARD RGB_DIRTY = true; #endif } return false; case RGB_SPI: if (record->event.pressed) { rgblight_increase_speed(); } return false; case RGB_SPD: if (record->event.pressed) { rgblight_decrease_speed(); } return false; case RGB_MODE_PLAIN: if (record->event.pressed) { rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); #ifdef SPLIT_KEYBOARD RGB_DIRTY = true; #endif } return false; case RGB_MODE_BREATHE: #ifdef RGBLIGHT_EFFECT_BREATHING if (record->event.pressed) { if ((RGBLIGHT_MODE_BREATHING <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_BREATHING_end)) { rgblight_step(); } else { rgblight_mode(RGBLIGHT_MODE_BREATHING); } } #endif return false; case RGB_MODE_RAINBOW: #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD if (record->event.pressed) { if ((RGBLIGHT_MODE_RAINBOW_MOOD <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_RAINBOW_MOOD_end)) { rgblight_step(); } else { rgblight_mode(RGBLIGHT_MODE_RAINBOW_MOOD); } } #endif return false; case RGB_MODE_SWIRL: #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL if (record->event.pressed) { if ((RGBLIGHT_MODE_RAINBOW_SWIRL <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_RAINBOW_SWIRL_end)) { rgblight_step(); } else { rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL); } } #endif return false; case RGB_MODE_SNAKE: #ifdef RGBLIGHT_EFFECT_SNAKE if (record->event.pressed) { if ((RGBLIGHT_MODE_SNAKE <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_SNAKE_end)) { rgblight_step(); } else { rgblight_mode(RGBLIGHT_MODE_SNAKE); } } #endif return false; case RGB_MODE_KNIGHT: #ifdef RGBLIGHT_EFFECT_KNIGHT if (record->event.pressed) { if ((RGBLIGHT_MODE_KNIGHT <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_KNIGHT_end)) { rgblight_step(); } else { rgblight_mode(RGBLIGHT_MODE_KNIGHT); } } #endif return false; case RGB_MODE_XMAS: #ifdef RGBLIGHT_EFFECT_CHRISTMAS if (record->event.pressed) { rgblight_mode(RGBLIGHT_MODE_CHRISTMAS); } #endif return false; case RGB_MODE_GRADIENT: #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT if (record->event.pressed) { if ((RGBLIGHT_MODE_STATIC_GRADIENT <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_STATIC_GRADIENT_end)) { rgblight_step(); } else { rgblight_mode(RGBLIGHT_MODE_STATIC_GRADIENT); } } #endif return false; case RGB_MODE_RGBTEST: #ifdef RGBLIGHT_EFFECT_RGB_TEST if (record->event.pressed) { rgblight_mode(RGBLIGHT_MODE_RGB_TEST); } #endif return false; #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) #ifdef PROTOCOL_LUFA case OUT_AUTO: if (record->event.pressed) { set_output(OUTPUT_AUTO); } return false; case OUT_USB: if (record->event.pressed) { set_output(OUTPUT_USB); } return false; #ifdef BLUETOOTH_ENABLE case OUT_BT: if (record->event.pressed) { set_output(OUTPUT_BLUETOOTH); } return false; #endif #endif case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO: if (record->event.pressed) { // MAGIC actions (BOOTMAGIC without the boot) if (!eeconfig_is_enabled()) { eeconfig_init(); } /* keymap config */ keymap_config.raw = eeconfig_read_keymap(); switch (keycode) { case MAGIC_SWAP_CONTROL_CAPSLOCK: keymap_config.swap_control_capslock = true; break; case MAGIC_CAPSLOCK_TO_CONTROL: keymap_config.capslock_to_control = true; break; case MAGIC_SWAP_LALT_LGUI: keymap_config.swap_lalt_lgui = true; break; case MAGIC_SWAP_RALT_RGUI: keymap_config.swap_ralt_rgui = true; break; case MAGIC_NO_GUI: keymap_config.no_gui = true; break; case MAGIC_SWAP_GRAVE_ESC: keymap_config.swap_grave_esc = true; break; case MAGIC_SWAP_BACKSLASH_BACKSPACE: keymap_config.swap_backslash_backspace = true; break; case MAGIC_HOST_NKRO: keymap_config.nkro = true; break; case MAGIC_SWAP_ALT_GUI: keymap_config.swap_lalt_lgui = true; keymap_config.swap_ralt_rgui = true; #ifdef AUDIO_ENABLE PLAY_SONG(ag_swap_song); #endif break; case MAGIC_UNSWAP_CONTROL_CAPSLOCK: keymap_config.swap_control_capslock = false; break; case MAGIC_UNCAPSLOCK_TO_CONTROL: keymap_config.capslock_to_control = false; break; case MAGIC_UNSWAP_LALT_LGUI: keymap_config.swap_lalt_lgui = false; break; case MAGIC_UNSWAP_RALT_RGUI: keymap_config.swap_ralt_rgui = false; break; case MAGIC_UNNO_GUI: keymap_config.no_gui = false; break; case MAGIC_UNSWAP_GRAVE_ESC: keymap_config.swap_grave_esc = false; break; case MAGIC_UNSWAP_BACKSLASH_BACKSPACE: keymap_config.swap_backslash_backspace = false; break; case MAGIC_UNHOST_NKRO: keymap_config.nkro = false; break; case MAGIC_UNSWAP_ALT_GUI: keymap_config.swap_lalt_lgui = false; keymap_config.swap_ralt_rgui = false; #ifdef AUDIO_ENABLE PLAY_SONG(ag_norm_song); #endif break; case MAGIC_TOGGLE_ALT_GUI: keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui; keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui; #ifdef AUDIO_ENABLE if (keymap_config.swap_ralt_rgui) { PLAY_SONG(ag_swap_song); } else { PLAY_SONG(ag_norm_song); } #endif break; case MAGIC_TOGGLE_NKRO: keymap_config.nkro = !keymap_config.nkro; break; default: break; } eeconfig_update_keymap(keymap_config.raw); clear_keyboard(); // clear to prevent stuck keys return false; } break; case KC_LSPO: { if (record->event.pressed) { shift_interrupted[0] = false; scs_timer[0] = timer_read (); register_mods(MOD_BIT(KC_LSFT)); } else { #ifdef DISABLE_SPACE_CADET_ROLLOVER if (get_mods() & MOD_BIT(KC_RSFT)) { shift_interrupted[0] = true; shift_interrupted[1] = true; } #endif if (!shift_interrupted[0] && timer_elapsed(scs_timer[0]) < TAPPING_TERM) { register_code(LSPO_KEY); unregister_code(LSPO_KEY); } unregister_mods(MOD_BIT(KC_LSFT)); } return false; } case KC_RSPC: { if (record->event.pressed) { shift_interrupted[1] = false; scs_timer[1] = timer_read (); register_mods(MOD_BIT(KC_RSFT)); } else { #ifdef DISABLE_SPACE_CADET_ROLLOVER if (get_mods() & MOD_BIT(KC_LSFT)) { shift_interrupted[0] = true; shift_interrupted[1] = true; } #endif if (!shift_interrupted[1] && timer_elapsed(scs_timer[1]) < TAPPING_TERM) { register_code(RSPC_KEY); unregister_code(RSPC_KEY); } unregister_mods(MOD_BIT(KC_RSFT)); } return false; } case KC_SFTENT: { if (record->event.pressed) { shift_interrupted[1] = false; scs_timer[1] = timer_read (); register_mods(MOD_BIT(KC_RSFT)); } else if (!shift_interrupted[1] && timer_elapsed(scs_timer[1]) < TAPPING_TERM) { unregister_mods(MOD_BIT(KC_RSFT)); register_code(SFTENT_KEY); unregister_code(SFTENT_KEY); } else { unregister_mods(MOD_BIT(KC_RSFT)); } return false; } case GRAVE_ESC: { uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT) |MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI))); #ifdef GRAVE_ESC_ALT_OVERRIDE // if ALT is pressed, ESC is always sent // this is handy for the cmd+opt+esc shortcut on macOS, among other things. if (get_mods() & (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT))) { shifted = 0; } #endif #ifdef GRAVE_ESC_CTRL_OVERRIDE // if CTRL is pressed, ESC is always sent // this is handy for the ctrl+shift+esc shortcut on windows, among other things. if (get_mods() & (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL))) { shifted = 0; } #endif #ifdef GRAVE_ESC_GUI_OVERRIDE // if GUI is pressed, ESC is always sent if (get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI))) { shifted = 0; } #endif #ifdef GRAVE_ESC_SHIFT_OVERRIDE // if SHIFT is pressed, ESC is always sent if (get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) { shifted = 0; } #endif if (record->event.pressed) { grave_esc_was_shifted = shifted; add_key(shifted ? KC_GRAVE : KC_ESCAPE); } else { del_key(grave_esc_was_shifted ? KC_GRAVE : KC_ESCAPE); } send_keyboard_report(); return false; } #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_BREATHING) case BL_BRTG: { if (record->event.pressed) breathing_toggle(); return false; } #endif default: { shift_interrupted[0] = true; shift_interrupted[1] = true; break; } } return process_action_kb(record); } __attribute__ ((weak)) const bool ascii_to_shift_lut[0x80] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0 }; __attribute__ ((weak)) const uint8_t ascii_to_keycode_lut[0x80] PROGMEM = { 0, 0, 0, 0, 0, 0, 0, 0, KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, KC_ESC, 0, 0, 0, 0, KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT, KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH, KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH, KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS, KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G, KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O, KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W, KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL }; void send_string(const char *str) { send_string_with_delay(str, 0); } void send_string_P(const char *str) { send_string_with_delay_P(str, 0); } void send_string_with_delay(const char *str, uint8_t interval) { while (1) { char ascii_code = *str; if (!ascii_code) break; if (ascii_code == 1) { // tap uint8_t keycode = *(++str); register_code(keycode); unregister_code(keycode); } else if (ascii_code == 2) { // down uint8_t keycode = *(++str); register_code(keycode); } else if (ascii_code == 3) { // up uint8_t keycode = *(++str); unregister_code(keycode); } else { send_char(ascii_code); } ++str; // interval { uint8_t ms = interval; while (ms--) wait_ms(1); } } } void send_string_with_delay_P(const char *str, uint8_t interval) { while (1) { char ascii_code = pgm_read_byte(str); if (!ascii_code) break; if (ascii_code == 1) { // tap uint8_t keycode = pgm_read_byte(++str); register_code(keycode); unregister_code(keycode); } else if (ascii_code == 2) { // down uint8_t keycode = pgm_read_byte(++str); register_code(keycode); } else if (ascii_code == 3) { // up uint8_t keycode = pgm_read_byte(++str); unregister_code(keycode); } else { send_char(ascii_code); } ++str; // interval { uint8_t ms = interval; while (ms--) wait_ms(1); } } } void send_char(char ascii_code) { uint8_t keycode; keycode = pgm_read_byte(&ascii_to_keycode_lut[(uint8_t)ascii_code]); if (pgm_read_byte(&ascii_to_shift_lut[(uint8_t)ascii_code])) { register_code(KC_LSFT); register_code(keycode); unregister_code(keycode); unregister_code(KC_LSFT); } else { register_code(keycode); unregister_code(keycode); } } void set_single_persistent_default_layer(uint8_t default_layer) { #if defined(AUDIO_ENABLE) && defined(DEFAULT_LAYER_SONGS) PLAY_SONG(default_layer_songs[default_layer]); #endif eeconfig_update_default_layer(1U<<default_layer); default_layer_set(1U<<default_layer); } uint32_t update_tri_layer_state(uint32_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3) { uint32_t mask12 = (1UL << layer1) | (1UL << layer2); uint32_t mask3 = 1UL << layer3; return (state & mask12) == mask12 ? (state | mask3) : (state & ~mask3); } void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { layer_state_set(update_tri_layer_state(layer_state, layer1, layer2, layer3)); } void tap_random_base64(void) { #if defined(__AVR_ATmega32U4__) uint8_t key = (TCNT0 + TCNT1 + TCNT3 + TCNT4) % 64; #else uint8_t key = rand() % 64; #endif switch (key) { case 0 ... 25: register_code(KC_LSFT); register_code(key + KC_A); unregister_code(key + KC_A); unregister_code(KC_LSFT); break; case 26 ... 51: register_code(key - 26 + KC_A); unregister_code(key - 26 + KC_A); break; case 52: register_code(KC_0); unregister_code(KC_0); break; case 53 ... 61: register_code(key - 53 + KC_1); unregister_code(key - 53 + KC_1); break; case 62: register_code(KC_LSFT); register_code(KC_EQL); unregister_code(KC_EQL); unregister_code(KC_LSFT); break; case 63: register_code(KC_SLSH); unregister_code(KC_SLSH); break; } }
bool process_record_quantum(keyrecord_t *record) { /* This gets the keycode from the key pressed */ keypos_t key = record->event.key; uint16_t keycode; #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) /* TODO: Use store_or_get_action() or a similar function. */ if (!disable_action_cache) { uint8_t layer; if (record->event.pressed) { layer = layer_switch_get_layer(key); update_source_layers_cache(key, layer); } else { layer = read_source_layers_cache(key); } keycode = keymap_key_to_keycode(layer, key); } else #endif keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key); // This is how you use actions here // if (keycode == KC_LEAD) { // action_t action; // action.code = ACTION_DEFAULT_LAYER_SET(0); // process_action(record, action); // return false; // } if (!( #if defined(KEY_LOCK_ENABLE) // Must run first to be able to mask key_up events. process_key_lock(&keycode, record) && #endif process_record_kb(keycode, record) && #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) process_midi(keycode, record) && #endif #ifdef AUDIO_ENABLE process_audio(keycode, record) && #endif #ifdef STENO_ENABLE process_steno(keycode, record) && #endif #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) process_music(keycode, record) && #endif #ifdef TAP_DANCE_ENABLE process_tap_dance(keycode, record) && #endif #ifndef DISABLE_LEADER process_leader(keycode, record) && #endif #ifndef DISABLE_CHORDING process_chording(keycode, record) && #endif #ifdef COMBO_ENABLE process_combo(keycode, record) && #endif #ifdef UNICODE_ENABLE process_unicode(keycode, record) && #endif #ifdef UCIS_ENABLE process_ucis(keycode, record) && #endif #ifdef PRINTING_ENABLE process_printer(keycode, record) && #endif #ifdef AUTO_SHIFT_ENABLE process_auto_shift(keycode, record) && #endif #ifdef UNICODEMAP_ENABLE process_unicode_map(keycode, record) && #endif #ifdef TERMINAL_ENABLE process_terminal(keycode, record) && #endif true)) { return false; } // Shift / paren setup switch(keycode) { case RESET: if (record->event.pressed) { reset_keyboard(); } return false; case DEBUG: if (record->event.pressed) { debug_enable = true; print("DEBUG: enabled.\n"); } return false; #ifdef FAUXCLICKY_ENABLE case FC_TOG: if (record->event.pressed) { FAUXCLICKY_TOGGLE; } return false; case FC_ON: if (record->event.pressed) { FAUXCLICKY_ON; } return false; case FC_OFF: if (record->event.pressed) { FAUXCLICKY_OFF; } return false; #endif #ifdef RGBLIGHT_ENABLE case RGB_TOG: if (record->event.pressed) { rgblight_toggle(); } return false; case RGB_MOD: if (record->event.pressed) { rgblight_step(); } return false; case RGB_SMOD: // same as RBG_MOD, but if shift is pressed, it will use the reverese direction instead. if (record->event.pressed) { uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT)); if(shifted) { rgblight_step_reverse(); } else { rgblight_step(); } } return false; case RGB_HUI: if (record->event.pressed) { rgblight_increase_hue(); } return false; case RGB_HUD: if (record->event.pressed) { rgblight_decrease_hue(); } return false; case RGB_SAI: if (record->event.pressed) { rgblight_increase_sat(); } return false; case RGB_SAD: if (record->event.pressed) { rgblight_decrease_sat(); } return false; case RGB_VAI: if (record->event.pressed) { rgblight_increase_val(); } return false; case RGB_VAD: if (record->event.pressed) { rgblight_decrease_val(); } return false; case RGB_MODE_PLAIN: if (record->event.pressed) { rgblight_mode(1); } return false; case RGB_MODE_BREATHE: if (record->event.pressed) { if ((2 <= rgblight_get_mode()) && (rgblight_get_mode() < 5)) { rgblight_step(); } else { rgblight_mode(2); } } return false; case RGB_MODE_RAINBOW: if (record->event.pressed) { if ((6 <= rgblight_get_mode()) && (rgblight_get_mode() < 8)) { rgblight_step(); } else { rgblight_mode(6); } } return false; case RGB_MODE_SWIRL: if (record->event.pressed) { if ((9 <= rgblight_get_mode()) && (rgblight_get_mode() < 14)) { rgblight_step(); } else { rgblight_mode(9); } } return false; case RGB_MODE_SNAKE: if (record->event.pressed) { if ((15 <= rgblight_get_mode()) && (rgblight_get_mode() < 20)) { rgblight_step(); } else { rgblight_mode(15); } } return false; case RGB_MODE_KNIGHT: if (record->event.pressed) { if ((21 <= rgblight_get_mode()) && (rgblight_get_mode() < 23)) { rgblight_step(); } else { rgblight_mode(21); } } return false; case RGB_MODE_XMAS: if (record->event.pressed) { rgblight_mode(24); } return false; case RGB_MODE_GRADIENT: if (record->event.pressed) { if ((25 <= rgblight_get_mode()) && (rgblight_get_mode() < 34)) { rgblight_step(); } else { rgblight_mode(25); } } return false; #endif #ifdef PROTOCOL_LUFA case OUT_AUTO: if (record->event.pressed) { set_output(OUTPUT_AUTO); } return false; case OUT_USB: if (record->event.pressed) { set_output(OUTPUT_USB); } return false; #ifdef BLUETOOTH_ENABLE case OUT_BT: if (record->event.pressed) { set_output(OUTPUT_BLUETOOTH); } return false; #endif #endif case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO: if (record->event.pressed) { // MAGIC actions (BOOTMAGIC without the boot) if (!eeconfig_is_enabled()) { eeconfig_init(); } /* keymap config */ keymap_config.raw = eeconfig_read_keymap(); switch (keycode) { case MAGIC_SWAP_CONTROL_CAPSLOCK: keymap_config.swap_control_capslock = true; break; case MAGIC_CAPSLOCK_TO_CONTROL: keymap_config.capslock_to_control = true; break; case MAGIC_SWAP_LALT_LGUI: keymap_config.swap_lalt_lgui = true; break; case MAGIC_SWAP_RALT_RGUI: keymap_config.swap_ralt_rgui = true; break; case MAGIC_NO_GUI: keymap_config.no_gui = true; break; case MAGIC_SWAP_GRAVE_ESC: keymap_config.swap_grave_esc = true; break; case MAGIC_SWAP_BACKSLASH_BACKSPACE: keymap_config.swap_backslash_backspace = true; break; case MAGIC_HOST_NKRO: keymap_config.nkro = true; break; case MAGIC_SWAP_ALT_GUI: keymap_config.swap_lalt_lgui = true; keymap_config.swap_ralt_rgui = true; #ifdef AUDIO_ENABLE PLAY_SONG(ag_swap_song); #endif break; case MAGIC_UNSWAP_CONTROL_CAPSLOCK: keymap_config.swap_control_capslock = false; break; case MAGIC_UNCAPSLOCK_TO_CONTROL: keymap_config.capslock_to_control = false; break; case MAGIC_UNSWAP_LALT_LGUI: keymap_config.swap_lalt_lgui = false; break; case MAGIC_UNSWAP_RALT_RGUI: keymap_config.swap_ralt_rgui = false; break; case MAGIC_UNNO_GUI: keymap_config.no_gui = false; break; case MAGIC_UNSWAP_GRAVE_ESC: keymap_config.swap_grave_esc = false; break; case MAGIC_UNSWAP_BACKSLASH_BACKSPACE: keymap_config.swap_backslash_backspace = false; break; case MAGIC_UNHOST_NKRO: keymap_config.nkro = false; break; case MAGIC_UNSWAP_ALT_GUI: keymap_config.swap_lalt_lgui = false; keymap_config.swap_ralt_rgui = false; #ifdef AUDIO_ENABLE PLAY_SONG(ag_norm_song); #endif break; case MAGIC_TOGGLE_NKRO: keymap_config.nkro = !keymap_config.nkro; break; default: break; } eeconfig_update_keymap(keymap_config.raw); clear_keyboard(); // clear to prevent stuck keys return false; } break; case KC_LSPO: { if (record->event.pressed) { shift_interrupted[0] = false; scs_timer[0] = timer_read (); register_mods(MOD_BIT(KC_LSFT)); } else { #ifdef DISABLE_SPACE_CADET_ROLLOVER if (get_mods() & MOD_BIT(KC_RSFT)) { shift_interrupted[0] = true; shift_interrupted[1] = true; } #endif if (!shift_interrupted[0] && timer_elapsed(scs_timer[0]) < TAPPING_TERM) { register_code(LSPO_KEY); unregister_code(LSPO_KEY); } unregister_mods(MOD_BIT(KC_LSFT)); } return false; } case KC_RSPC: { if (record->event.pressed) { shift_interrupted[1] = false; scs_timer[1] = timer_read (); register_mods(MOD_BIT(KC_RSFT)); } else { #ifdef DISABLE_SPACE_CADET_ROLLOVER if (get_mods() & MOD_BIT(KC_LSFT)) { shift_interrupted[0] = true; shift_interrupted[1] = true; } #endif if (!shift_interrupted[1] && timer_elapsed(scs_timer[1]) < TAPPING_TERM) { register_code(RSPC_KEY); unregister_code(RSPC_KEY); } unregister_mods(MOD_BIT(KC_RSFT)); } return false; } case GRAVE_ESC: { uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT) |MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI))); #ifdef GRAVE_ESC_ALT_OVERRIDE // if ALT is pressed, ESC is always sent // this is handy for the cmd+opt+esc shortcut on macOS, among other things. if (get_mods() & (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT))) { shifted = 0; } #endif #ifdef GRAVE_ESC_CTRL_OVERRIDE // if CTRL is pressed, ESC is always sent // this is handy for the ctrl+shift+esc shortcut on windows, among other things. if (get_mods() & (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL))) { shifted = 0; } #endif #ifdef GRAVE_ESC_GUI_OVERRIDE // if GUI is pressed, ESC is always sent if (get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI))) { shifted = 0; } #endif #ifdef GRAVE_ESC_SHIFT_OVERRIDE // if SHIFT is pressed, ESC is always sent if (get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) { shifted = 0; } #endif if (record->event.pressed) { grave_esc_was_shifted = shifted; add_key(shifted ? KC_GRAVE : KC_ESCAPE); } else { del_key(grave_esc_was_shifted ? KC_GRAVE : KC_ESCAPE); } send_keyboard_report(); } default: { shift_interrupted[0] = true; shift_interrupted[1] = true; break; } } return process_action_kb(record); }
static void port_event(LV2UI_Handle handle, uint32_t port_index, uint32_t buffer_size, uint32_t format, const void* buffer) { SFSUI* ui = (SFSUI*)handle; LV2_Atom* atom = (LV2_Atom*)buffer; if (format == ui->uris.atom_eventTransfer && (atom->type == ui->uris.atom_Blank|| atom->type == ui->uris.atom_Object)) { /* cast the buffer to Atom Object */ LV2_Atom_Object* obj = (LV2_Atom_Object*)atom; LV2_Atom *a0 = NULL; LV2_Atom *a1 = NULL; if (obj->body.otype == ui->uris.rawstereo && 2 == lv2_atom_object_get(obj, ui->uris.audioleft, &a0, ui->uris.audioright, &a1, NULL) && a0 && a1 && a0->type == ui->uris.atom_Vector && a1->type == ui->uris.atom_Vector ) { LV2_Atom_Vector* left = (LV2_Atom_Vector*)LV2_ATOM_BODY(a0); LV2_Atom_Vector* right = (LV2_Atom_Vector*)LV2_ATOM_BODY(a1); if (left->atom.type == ui->uris.atom_Float && right->atom.type == ui->uris.atom_Float) { const size_t n_elem = (a0->size - sizeof(LV2_Atom_Vector_Body)) / left->atom.size; const float *l = (float*) LV2_ATOM_BODY(&left->atom); const float *r = (float*) LV2_ATOM_BODY(&right->atom); process_audio(ui, n_elem, l, r); } } else if ( /* handle 'state/settings' data object */ obj->body.otype == ui->uris.ui_state /* retrieve properties from object and * check that there the [here] three required properties are set.. */ && 1 == lv2_atom_object_get(obj, ui->uris.samplerate, &a0, NULL) /* ..and non-null.. */ && a0 /* ..and match the expected type */ && a0->type == ui->uris.atom_Float ) { ui->rate = ((LV2_Atom_Float*)a0)->body; reinitialize_fft(ui, ui->fft_bins); } } else if (format != 0) return; if (port_index == SS_FFT) { float val = *(float *)buffer; uint32_t fft_bins = floorf(val / 2.0); if (ui->fft_bins != fft_bins) { reinitialize_fft(ui, fft_bins); robtk_select_set_value(ui->sel_fft, ui->fft_bins); } } else if (port_index == SS_BAND) { float val = *(float *)buffer; ui->disable_signals = true; robtk_cbtn_set_active(ui->btn_oct, val != 0); ui->disable_signals = false; } else if (port_index == SS_SCREEN) { ui->disable_signals = true; robtk_dial_set_value(ui->screen, *(float *)buffer); ui->disable_signals = false; } }
bool process_record_quantum(keyrecord_t *record) { /* This gets the keycode from the key pressed */ keypos_t key = record->event.key; uint16_t keycode; #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) /* TODO: Use store_or_get_action() or a similar function. */ if (!disable_action_cache) { uint8_t layer; if (record->event.pressed) { layer = layer_switch_get_layer(key); update_source_layers_cache(key, layer); } else { layer = read_source_layers_cache(key); } keycode = keymap_key_to_keycode(layer, key); } else #endif keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key); // This is how you use actions here // if (keycode == KC_LEAD) { // action_t action; // action.code = ACTION_DEFAULT_LAYER_SET(0); // process_action(record, action); // return false; // } if (!( process_record_kb(keycode, record) && #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) process_midi(keycode, record) && #endif #ifdef AUDIO_ENABLE process_audio(keycode, record) && #endif #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) process_music(keycode, record) && #endif #ifdef TAP_DANCE_ENABLE process_tap_dance(keycode, record) && #endif #ifndef DISABLE_LEADER process_leader(keycode, record) && #endif #ifndef DISABLE_CHORDING process_chording(keycode, record) && #endif #ifdef COMBO_ENABLE process_combo(keycode, record) && #endif #ifdef UNICODE_ENABLE process_unicode(keycode, record) && #endif #ifdef UCIS_ENABLE process_ucis(keycode, record) && #endif #ifdef PRINTING_ENABLE process_printer(keycode, record) && #endif #ifdef UNICODEMAP_ENABLE process_unicode_map(keycode, record) && #endif true)) { return false; } // Shift / paren setup switch(keycode) { case RESET: if (record->event.pressed) { reset_keyboard(); } return false; break; case DEBUG: if (record->event.pressed) { print("\nDEBUG: enabled.\n"); debug_enable = true; } return false; break; #ifdef FAUXCLICKY_ENABLE case FC_TOG: if (record->event.pressed) { FAUXCLICKY_TOGGLE; } return false; break; case FC_ON: if (record->event.pressed) { FAUXCLICKY_ON; } return false; break; case FC_OFF: if (record->event.pressed) { FAUXCLICKY_OFF; } return false; break; #endif #ifdef RGBLIGHT_ENABLE case RGB_TOG: if (record->event.pressed) { rgblight_toggle(); } return false; break; case RGB_MOD: if (record->event.pressed) { rgblight_step(); } return false; break; case RGB_HUI: if (record->event.pressed) { rgblight_increase_hue(); } return false; break; case RGB_HUD: if (record->event.pressed) { rgblight_decrease_hue(); } return false; break; case RGB_SAI: if (record->event.pressed) { rgblight_increase_sat(); } return false; break; case RGB_SAD: if (record->event.pressed) { rgblight_decrease_sat(); } return false; break; case RGB_VAI: if (record->event.pressed) { rgblight_increase_val(); } return false; break; case RGB_VAD: if (record->event.pressed) { rgblight_decrease_val(); } return false; break; #endif #ifdef PROTOCOL_LUFA case OUT_AUTO: if (record->event.pressed) { set_output(OUTPUT_AUTO); } return false; break; case OUT_USB: if (record->event.pressed) { set_output(OUTPUT_USB); } return false; break; #ifdef BLUETOOTH_ENABLE case OUT_BT: if (record->event.pressed) { set_output(OUTPUT_BLUETOOTH); } return false; break; #endif #endif case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO: if (record->event.pressed) { // MAGIC actions (BOOTMAGIC without the boot) if (!eeconfig_is_enabled()) { eeconfig_init(); } /* keymap config */ keymap_config.raw = eeconfig_read_keymap(); switch (keycode) { case MAGIC_SWAP_CONTROL_CAPSLOCK: keymap_config.swap_control_capslock = true; break; case MAGIC_CAPSLOCK_TO_CONTROL: keymap_config.capslock_to_control = true; break; case MAGIC_SWAP_LALT_LGUI: keymap_config.swap_lalt_lgui = true; break; case MAGIC_SWAP_RALT_RGUI: keymap_config.swap_ralt_rgui = true; break; case MAGIC_NO_GUI: keymap_config.no_gui = true; break; case MAGIC_SWAP_GRAVE_ESC: keymap_config.swap_grave_esc = true; break; case MAGIC_SWAP_BACKSLASH_BACKSPACE: keymap_config.swap_backslash_backspace = true; break; case MAGIC_HOST_NKRO: keymap_config.nkro = true; break; case MAGIC_SWAP_ALT_GUI: keymap_config.swap_lalt_lgui = true; keymap_config.swap_ralt_rgui = true; break; case MAGIC_UNSWAP_CONTROL_CAPSLOCK: keymap_config.swap_control_capslock = false; break; case MAGIC_UNCAPSLOCK_TO_CONTROL: keymap_config.capslock_to_control = false; break; case MAGIC_UNSWAP_LALT_LGUI: keymap_config.swap_lalt_lgui = false; break; case MAGIC_UNSWAP_RALT_RGUI: keymap_config.swap_ralt_rgui = false; break; case MAGIC_UNNO_GUI: keymap_config.no_gui = false; break; case MAGIC_UNSWAP_GRAVE_ESC: keymap_config.swap_grave_esc = false; break; case MAGIC_UNSWAP_BACKSLASH_BACKSPACE: keymap_config.swap_backslash_backspace = false; break; case MAGIC_UNHOST_NKRO: keymap_config.nkro = false; break; case MAGIC_UNSWAP_ALT_GUI: keymap_config.swap_lalt_lgui = false; keymap_config.swap_ralt_rgui = false; break; case MAGIC_TOGGLE_NKRO: keymap_config.nkro = !keymap_config.nkro; break; default: break; } eeconfig_update_keymap(keymap_config.raw); clear_keyboard(); // clear to prevent stuck keys return false; } break; case KC_LSPO: { if (record->event.pressed) { shift_interrupted[0] = false; scs_timer[0] = timer_read (); register_mods(MOD_BIT(KC_LSFT)); } else { #ifdef DISABLE_SPACE_CADET_ROLLOVER if (get_mods() & MOD_BIT(KC_RSFT)) { shift_interrupted[0] = true; shift_interrupted[1] = true; } #endif if (!shift_interrupted[0] && timer_elapsed(scs_timer[0]) < TAPPING_TERM) { register_code(LSPO_KEY); unregister_code(LSPO_KEY); } unregister_mods(MOD_BIT(KC_LSFT)); } return false; // break; } case KC_RSPC: { if (record->event.pressed) { shift_interrupted[1] = false; scs_timer[1] = timer_read (); register_mods(MOD_BIT(KC_RSFT)); } else { #ifdef DISABLE_SPACE_CADET_ROLLOVER if (get_mods() & MOD_BIT(KC_LSFT)) { shift_interrupted[0] = true; shift_interrupted[1] = true; } #endif if (!shift_interrupted[1] && timer_elapsed(scs_timer[1]) < TAPPING_TERM) { register_code(RSPC_KEY); unregister_code(RSPC_KEY); } unregister_mods(MOD_BIT(KC_RSFT)); } return false; // break; } case GRAVE_ESC: { void (*method)(uint8_t) = (record->event.pressed) ? &add_key : &del_key; uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT) |MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI))); method(shifted ? KC_GRAVE : KC_ESCAPE); send_keyboard_report(); } default: { shift_interrupted[0] = true; shift_interrupted[1] = true; break; } } return process_action_kb(record); }
int film::process () { int audioSize; uint8_t *buffer; uint8_t *buffer2; int frameFinished; int numBytes; shot s; static struct SwsContext *img_convert_ctx = NULL; create_main_dir (); string graphpath = this->global_path + "/"; g = new graph (600, 400, graphpath, threshold, this); g->set_title ("Motion quantity"); /* * Register all formats and codecs */ av_register_all (); if (av_open_input_file (&pFormatCtx, input_path.c_str (), NULL, 0, NULL) != 0) { string error_msg = "Impossible to open file"; error_msg += input_path; shotlog (error_msg); return -1; // Couldn't open file } /* * Retrieve stream information */ if (av_find_stream_info (pFormatCtx) < 0) return -1; // Couldn't find stream information // dump_format (pFormatCtx, 0, path.c_str (), false); videoStream = -1; audioStream = -1; /* * Detect streams types */ for (int j = 0; j < pFormatCtx->nb_streams; j++) { switch (pFormatCtx->streams[j]->codec->codec_type) { case AVMEDIA_TYPE_VIDEO: videoStream = j; break; case AVMEDIA_TYPE_AUDIO: audioStream = j; break; default: break; } } /* * Get a pointer to the codec context for the video stream */ if (audioStream != -1) { if (audio_set) { string xml_audio = graphpath + "/" + "audio.xml"; init_xml (xml_audio); } pCodecCtxAudio = pFormatCtx->streams[audioStream]->codec; pCodecAudio = avcodec_find_decoder (pCodecCtxAudio->codec_id); if (pCodecAudio == NULL) return -1; // Codec not found if (avcodec_open (pCodecCtxAudio, pCodecAudio) < 0) return -1; // Could not open codec } update_metadata (); /* * Find the decoder for the video stream */ if (videoStream != -1) { pCodecCtx = pFormatCtx->streams[videoStream]->codec; pCodec = avcodec_find_decoder (pCodecCtx->codec_id); if (pCodec == NULL) return -1; // Codec not found if (avcodec_open (pCodecCtx, pCodec) < 0) return -1; // Could not open codec /* * Allocate video frame */ pFrame = avcodec_alloc_frame (); pFrameRGB = avcodec_alloc_frame (); pFrameRGBprev = avcodec_alloc_frame (); /* * Determine required buffer size and allocate buffer */ numBytes = avpicture_get_size (PIX_FMT_RGB24, width, height); buffer = (uint8_t *) malloc (sizeof (uint8_t) * numBytes); buffer2 = (uint8_t *) malloc (sizeof (uint8_t) * numBytes); /* * Assign appropriate parts of buffer to image planes in pFrameRGB */ avpicture_fill ((AVPicture *) pFrameRGB, buffer, PIX_FMT_RGB24, width, height); avpicture_fill ((AVPicture *) pFrameRGBprev, buffer2, PIX_FMT_RGB24, width, height); /* * Mise en place du premier plan */ s.fbegin = 0; s.msbegin = 0; s.myid = 0; shots.push_back (s); } checknumber = (samplerate * samplearg) / 1000; /* * Boucle de traitement principale du flux */ this->frame_number = 0; while (av_read_frame (pFormatCtx, &packet) >= 0) { if (packet.stream_index == videoStream) { AVPacket pkt; av_init_packet (&pkt); pkt.data = packet.data; pkt.size = packet.size; avcodec_decode_video2 (pCodecCtx, pFrame, &frameFinished, &pkt); if (frameFinished) { // Convert the image into RGB24 if (! img_convert_ctx) { img_convert_ctx = sws_getContext(width, height, pCodecCtx->pix_fmt, width, height, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL); if (! img_convert_ctx) { fprintf(stderr, "Cannot initialize the conversion context!\n"); exit(1); } } /* API: int sws_scale(SwsContext *c, uint8_t *src, int srcStride[], int srcSliceY, int srcSliceH, uint8_t dst[], int dstStride[] ) */ sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize); /* Old API doc (cf http://www.dranger.com/ffmpeg/functions.html ) int img_convert(AVPicture *dst, int dst_pix_fmt, const AVPicture *src, int src_pix_fmt, int src_width, int src_height) */ /* img_convert ((AVPicture *) pFrameRGB, PIX_FMT_RGB24, (AVPicture *) pFrame, pCodecCtx->pix_fmt, width, height); */ this->frame_number ++; /* Si ce n'est pas la permiere image */ if ( this->frame_number > 2) { CompareFrame (pFrameRGB, pFrameRGBprev); } else { /* * Cas ou c'est la premiere image, on cree la premiere image dans tous les cas */ image *begin_i = new image (this, width, height, s.myid, BEGIN); begin_i->create_img_dir (); begin_i->SaveFrame (pFrameRGB); shots.back ().img_begin = begin_i; } memcpy (buffer2, buffer, numBytes); } } if (audio_set && (packet.stream_index == audioStream)) { process_audio (); } /* * Free the packet that was allocated by av_read_frame */ if (packet.data != NULL) av_free_packet (&packet); } if (videoStream != -1) { /* Mise en place de la dernière image */ int lastFrame = this->frame_number; shots.back ().fduration = lastFrame - shots.back ().fbegin; shots.back ().msduration = int (((shots.back ().fduration) * 1000) / fps); duration.mstotal = int (shots.back ().msduration + shots.back ().msbegin); image *end_i = new image (this, width, height, shots.back ().myid, END); end_i->SaveFrame (pFrameRGB); shots.back ().img_end = end_i; /* * Graphe de la qté de mvmt */ g->init_gd (); g->draw_all_canvas (); g->draw_color_datas (); g->draw_datas (); if (video_set) { string xml_color = graphpath + "/" + "video.xml"; g->write_xml (xml_color); } g->save (); /* * Free the RGB images */ free (buffer); free (buffer2); av_free (pFrameRGB); av_free (pFrame); av_free (pFrameRGBprev); avcodec_close (pCodecCtx); } /* * Close the codec */ if (audioStream != -1) { /* Fermetrure du fichier xml */ if (audio_set) close_xml (); avcodec_close (pCodecCtxAudio); } /* * Close the video file */ av_close_input_file (pFormatCtx); }
bool obs_transition_audio_render(obs_source_t *transition, uint64_t *ts_out, struct obs_source_audio_mix *audio, uint32_t mixers, size_t channels, size_t sample_rate, obs_transition_audio_mix_callback_t mix_a, obs_transition_audio_mix_callback_t mix_b) { obs_source_t *sources[2]; struct transition_state state = {0}; bool stopped = false; uint64_t min_ts; float t; if (!transition_valid(transition, "obs_transition_audio_render")) return false; lock_transition(transition); sources[0] = transition->transition_sources[0]; sources[1] = transition->transition_sources[1]; min_ts = calc_min_ts(sources); if (min_ts) { t = calc_time(transition, min_ts); if (t >= 1.0f && transition->transitioning_audio) stopped = stop_audio(transition); sources[0] = transition->transition_sources[0]; sources[1] = transition->transition_sources[1]; min_ts = calc_min_ts(sources); if (min_ts) copy_transition_state(transition, &state); } else if (transition->transitioning_audio) { stopped = stop_audio(transition); } unlock_transition(transition); if (min_ts) { if (state.transitioning_audio) { if (state.s[0]) process_audio(transition, state.s[0], audio, min_ts, mixers, channels, sample_rate, mix_a); if (state.s[1]) process_audio(transition, state.s[1], audio, min_ts, mixers, channels, sample_rate, mix_b); } else if (state.s[0]) { memcpy(audio->output[0].data[0], state.s[0]->audio_output_buf[0][0], TOTAL_AUDIO_SIZE); } obs_source_release(state.s[0]); obs_source_release(state.s[1]); } if (stopped) obs_source_dosignal(transition, "source_transition_stop", "transition_stop"); *ts_out = min_ts; return !!min_ts; }
void synth_main() { gfx_wave_render_initialise(); gfx_envelope_render_initialise(); create_settings(); create_ui(); gfx_event_initialise(); gfx_initialise(); patch_initialise(); synth_initialise(); configure_audio(); configure_profiling(); config_setting_t* piglow_config = config_lookup(&app_config, CFG_DEVICES_PIGLOW); if (piglow_config != NULL) { piglow_initialise(piglow_config); } waveform_initialise(); gfx_register_event_global_handler(GFX_EVENT_BUFFERSWAP, process_buffer_swap); // Done after synth setup as this can load controller values into the synth configure_midi(); int profiling = 0; int32_t last_timestamp = get_elapsed_time_ms(); while (1) { int midi_controller_value; if (midi_controller_update_and_read(&exit_controller, &midi_controller_value)) { break; } if (midi_controller_update_and_read(&screenshot_controller, &midi_controller_value)) { static int screenshot_count = 0; char screenshot_name[64]; sprintf(screenshot_name, "pithesiser-img-%03d.png", screenshot_count++); gfx_screenshot(screenshot_name); } process_midi_events(); if (!profiling && midi_controller_update_and_read(&profile_controller, &midi_controller_value)) { if (profile_file != NULL) { ProfilerStart(profile_file); profiling = 1; } } alsa_sync_with_audio_output(); int32_t timestamp = get_elapsed_time_ms(); process_audio(timestamp - last_timestamp); last_timestamp = timestamp; } if (profiling) { ProfilerStop(); } synth_controllers_save(SETTINGS_FILE); patch_save(); patch_deinitialise(); piglow_deinitialise(); gfx_deinitialise(); destroy_ui(); gfx_envelope_render_deinitialise(); gfx_wave_render_deinitialise(); mod_matrix_controller_deinitialise(); alsa_deinitialise(); midi_deinitialise(); synth_deinitialise(); config_destroy(&app_config); LOG_INFO("Done: %d xruns", alsa_get_xruns_count()); }