// Adds an event to a path. An event can only be added if the event's object id // matches the path's object id. // // path - The path to add the event to. // event - The event to add to the path. // // Returns 0 if successful, otherwise returns -1. int sky_path_add_event(sky_path *path, sky_event *event) { // Validation. check(path != NULL, "Path required"); check(path->object_id != 0, "Path object id cannot be null"); check(event != NULL, "Event required"); check(path->object_id == event->object_id, "Event object id (%d) does not match path object id (%d)", event->object_id, path->object_id); // Raise error if event has already been added. unsigned int i; for(i=0; i<path->event_count; i++) { if(path->events[i] == event) { sentinel("Event has already been added to path"); } } // Allocate space for event. path->event_count++; path->events = realloc(path->events, sizeof(sky_event*) * path->event_count); check_mem(path->events); // Append event to the end. path->events[path->event_count-1] = event; // Sort events. sort_events(path); return 0; error: return -1; }
virtual status_t Import(SDL_RWops *rw) { fEvs = CreateMIDIEventList(rw, &fDivision); if (!fEvs) { return B_BAD_MIDI_DATA; } fTotal = 0; for (MIDIEvent *x = fEvs; x; x = x->next) fTotal++; fPos = fTotal; sort_events(); return B_OK; }
// Removes an event from a path. // // path - The path that contains the event. // event - The event to remove. // // Returns 0 if successful, otherwise returns -1. int sky_path_remove_event(sky_path *path, sky_event *event) { // Validation. check(path != NULL, "Path required"); check(event != NULL, "Event required"); // Find event. unsigned int i, j; for(i=0; i<path->event_count; i++) { if(path->events[i] == event) { // Shift events over. for(j=i+1; j<path->event_count; j++) { path->events[j-1] = path->events[j]; } // Reallocate memory. path->event_count--; if(path->event_count == 0) { free(path->events); path->events = NULL; } else { path->events = realloc(path->events, sizeof(sky_event*) * path->event_count); check_mem(path->events); } break; } } // Sort events. sort_events(path); return 0; error: return -1; }
void emplace_back_entry(device_id device_id, const event_time_stamp& event_time_stamp, const class event& event, event_type event_type, const class event& original_event, bool lazy = false) { auto t = event_time_stamp; t.set_time_stamp(t.get_time_stamp() + time_stamp_delay_); events_.emplace_back(device_id, t, event, event_type, original_event, lazy); sort_events(); // Update modifier_flag_manager if (auto key_code = event.get_key_code()) { if (auto modifier_flag = types::make_modifier_flag(*key_code)) { auto type = (event_type == event_type::key_down ? modifier_flag_manager::active_modifier_flag::type::increase : modifier_flag_manager::active_modifier_flag::type::decrease); modifier_flag_manager::active_modifier_flag active_modifier_flag(type, *modifier_flag, device_id); modifier_flag_manager_.push_back_active_modifier_flag(active_modifier_flag); } } if (event.get_type() == event::type::caps_lock_state_changed) { if (auto integer_value = event.get_integer_value()) { auto type = (*integer_value ? modifier_flag_manager::active_modifier_flag::type::increase_lock : modifier_flag_manager::active_modifier_flag::type::decrease_lock); modifier_flag_manager::active_modifier_flag active_modifier_flag(type, modifier_flag::caps_lock, device_id); modifier_flag_manager_.push_back_active_modifier_flag(active_modifier_flag); } } // Update pointing_button_manager if (auto pointing_button = event.get_pointing_button()) { if (*pointing_button != pointing_button::zero) { auto type = (event_type == event_type::key_down ? pointing_button_manager::active_pointing_button::type::increase : pointing_button_manager::active_pointing_button::type::decrease); pointing_button_manager::active_pointing_button active_pointing_button(type, *pointing_button, device_id); pointing_button_manager_.push_back_active_pointing_button(active_pointing_button); } } // Update manipulator_environment if (event.get_type() == event::type::device_grabbed) { if (auto v = event.find<device_properties>()) { manipulator_environment_.insert_device_properties(device_id, *v); } } if (event.get_type() == event::type::device_ungrabbed) { manipulator_environment_.erase_device_properties(device_id); } if (auto frontmost_application = event.get_frontmost_application()) { manipulator_environment_.set_frontmost_application(*frontmost_application); } if (auto properties = event.get_input_source_properties()) { manipulator_environment_.set_input_source_properties(*properties); } if (event_type == event_type::key_down) { if (auto set_variable = event.get_set_variable()) { manipulator_environment_.set_variable(set_variable->first, set_variable->second); } } if (auto properties = event.find<pqrs::osx::system_preferences::properties>()) { manipulator_environment_.set_system_preferences_properties(*properties); } if (auto code = event.find<hid_country_code>()) { manipulator_environment_.set_virtual_hid_keyboard_country_code(*code); } }