-
Notifications
You must be signed in to change notification settings - Fork 6
Services Layer
Five service classes bridge PadForge.Engine with the WPF UI layer. All live in PadForge.App/Services/ and run on the WPF dispatcher thread unless noted otherwise.
graph TB
MW[MainWindow]
IS[InputService]
SS[SettingsService]
DS[DeviceService]
RS[RecorderService]
FMS[ForegroundMonitorService]
IM[InputManager<br/>Polling Thread]
DSU[DsuMotionServer<br/>UDP Thread]
WCS[WebControllerServer<br/>HTTP Thread]
ABD[AudioBassDetector<br/>WASAPI Thread]
MW --> IS
MW --> SS
MW --> DS
MW --> RS
IS --> IM
IS --> DSU
IS --> WCS
IS --> ABD
IS --> FMS
SS -->|Load/Save XML| IS
DS -->|Device events| IS
IS -->|30Hz UI timer| MW
IM -->|1000Hz polling| IS
style IS fill:#f3e5f5
style IM fill:#e1f5fe
style DSU fill:#e8f5e9
style WCS fill:#e8f5e9
style ABD fill:#fff3e0
style FMS fill:#fff3e0
- Architecture Overview
- Threading Model
-
InputService
- Constructor and Initialization
- Start / Stop / Dispose
- 30Hz UI Timer Tick
- Dashboard Updates
- Devices Page Raw State
- Mapping Live Values
- Settings Sync (ViewModel to PadSetting)
- Settings Forwarding (OnSettingsPropertyChanged)
- Dashboard Forwarding (OnDashboardPropertyChanged)
- Engine Event Handlers
- Device List Sync
- Per-Device Settings Swap
- Copy / Paste Settings
- Macro Snapshot Sync
- Macro Trigger Recording
- DSU Server Lifecycle
- Web Controller Server Lifecycle
- Audio Bass Detector Lifecycle
- Device Hiding
- Auto-Idle
- Profile Switching
- Slot Reordering
- Test Rumble
- All Public Methods
- All Events
- SettingsService
- DeviceService
- RecorderService
- ForegroundMonitorService
+-------------------+ 30Hz Timer +-------------------+
| InputManager | ==================> | InputService |
| (background, | reads engine | (UI thread, |
| ~1000Hz poll) | state arrays | 30Hz timer) |
+-------------------+ +---------+---------+
^ |
| writes PadSettings, | pushes to ViewModels
| slot types, macro snapshots v
+-------------------+ +-------------------+
| SettingsManager | | MainViewModel |
| (static, shared) | <================= | PadViewModels |
+-------------------+ | DashboardVM |
^ | DevicesVM |
| | SettingsVM |
| +-------------------+
+-------------------+
| SettingsService |
| (XML load/save) |
+-------------------+
| Direction | Mechanism | Frequency |
|---|---|---|
| Engine -> UI | InputService reads CombinedOutputStates[], VibrationStates[], CombinedExtendedRawStates[], CombinedMidiRawStates[], CombinedKbmRawStates[]
|
30 Hz (UI timer) |
| UI -> Engine | InputService writes SlotControllerTypes[], SlotExtendedConfigs[], MacroSnapshots[], _midiConfigs[]
|
30 Hz (SyncViewModelToPadSettings) |
| UI -> PadSetting | InputService pushes deadzone, force feedback, mapping values to PadSetting objects | 30 Hz (SyncViewModelToPadSettings) |
| Engine event -> UI |
DevicesUpdated, FrequencyUpdated, ErrorOccurred marshalled via Dispatcher.BeginInvoke
|
On engine event |
| Settings file -> Memory | SettingsService deserializes XML into SettingsManager collections | On load |
| Memory -> Settings file | SettingsService serializes SettingsManager + ViewModel state to XML | On MarkDirty (250ms debounce) |
PadForge uses three primary threads. Knowing which thread owns what prevents race conditions.
| Thread | Owner | Rate | Responsibilities |
|---|---|---|---|
| UI thread (WPF Dispatcher) | MainWindow | 30 Hz timer | All ViewModel property writes, device list sync, dashboard updates, macro recording, profile switching, settings forwarding |
| Polling thread | InputManager | ~1000 Hz | SDL input read, mapping, deadzone processing, virtual controller output, rumble, DSU broadcast |
| Subsystem threads | Various | Varies | DSU server (UDP), Web controller (HTTP/WebSocket), Audio bass detector (WASAPI), HidHide controller |
| Data | Strategy |
|---|---|
SettingsManager collections (UserDevices, UserSettings) |
SyncRoot lock on both UI and polling threads |
| PadSetting string properties | Atomic reference assignment. UI writes at 30 Hz, polling reads at ~870 Hz |
InputManager arrays (CombinedOutputStates[], VibrationStates[], etc.) |
Simple value copies, no locking |
| Macro snapshots | Atomic array reference swap by UI thread. Polling thread reads the reference |
Engine events (DevicesUpdated, FrequencyUpdated) |
Fire on polling thread, marshalled to UI via Dispatcher.BeginInvoke
|
File: PadForge.App/Services/InputService.cs
Implements: IDisposable
Central service bridging the InputManager engine with WPF ViewModels. Owns the InputManager instance, runs the 30 Hz UI timer, and manages all subsystem lifecycles (DSU, web server, audio bass detector, foreground monitor, device hiding).
public InputService(MainViewModel mainVm)Constructor:
- Stores
MainViewModelreference, capturesDispatcher.CurrentDispatcher. - Subscribes to
Strings.CultureChangedfor language-change status refresh. - Subscribes to
SelectedDeviceChangedandMappingsRebuilton everyPadViewModel. - Subscribes to
DevicesViewModel.PropertyChangedfor offline device detail display. - Initializes
_previousSelectedDevicedictionary (tracks per-pad device GUID for save-before-switch).
Startup sequence:
- Cleanup stale HIDMaestro nodes. Removes USB device nodes from previous sessions (crash recovery).
-
Create InputManager. Sets
PollingIntervalMsfromSettingsViewModel.PollingRateMs. -
Copy slot config. Copies
SlotControllerTypes[], Extended/MIDI configs from PadViewModels to engine. -
Subscribe to engine events.
DevicesUpdated,FrequencyUpdated,ErrorOccurred. -
Subscribe to ViewModel changes.
SettingsViewModel.PropertyChanged,DashboardViewModel.PropertyChanged. -
Create ForegroundMonitorService. Subscribes to
ProfileSwitchRequired. -
Capture default profile snapshot. Uses
PendingDefaultSnapshot(from prior XML) or creates one viaSnapshotCurrentProfile(). -
Async Raw Input enumeration. Keyboard and mouse devices are discovered on a background thread via
Task.Run, preventing UI thread stalls from slow HID enumeration. Results are merged into the device list when the task completes. -
Start engine.
_inputManager.Start()launches the polling thread. - Start subsystems. DSU, web controller, audio bass detector (each conditional on settings).
-
Clear stale HidHide state.
HidHideController.ClearAll()removes leftover entries. - Apply device hiding. HidHide blacklist + input hooks.
-
Start UI timer. 30 Hz
DispatcherTimeratDispatcherPriority.Render. -
Update state. Sets
IsEngineRunning = true, enters idle if no slots created.
- Stops UI timer and unsubscribes from its Tick event.
- Unsubscribes from all ViewModel property change events.
- Unsubscribes from per-pad events (
SelectedDeviceChanged,MappingsRebuilt). - Disposes ForegroundMonitorService.
- Stops DSU server, web controller server, audio bass detector.
- Calls
RemoveDeviceHiding()(HidHide blacklist cleanup + input hook teardown). - Unsubscribes from engine events, calls
_inputManager.Stop()and_inputManager.Dispose(). - Updates MainViewModel state (sets engine status to "Stopped", marks all device rows offline).
The v2 preserveExtendedNodes parameter is gone. HIDMaestro creates and destroys virtual devices dynamically, so there's no need for the v2-era "keep the vJoy node alive across a restart" path.
Calls Stop() in a try/catch (best-effort shutdown).
UiTimer_Tick is the service layer heartbeat. Called ~30 times/second on the UI thread, it runs these steps in sequence:
UiTimer_Tick
|-- Update Pad ViewModels (gamepad state, vibration, Extended/MIDI/KBM raw state)
|-- UpdateDashboard()
|-- UpdateDevicesRawState() [only if Devices page visible]
|-- UpdateMappingLiveValues() [only if a Pad page visible]
|-- UpdateMacroTriggerRecording() [only if recording active]
|-- SyncViewModelToPadSettings() [always, 30Hz]
|-- SyncMacroSnapshots() [always, 30Hz]
|-- Audio rumble level meters [only if detector active]
|-- UpdateIdleState() [auto-idle when no active slots]
|-- ForegroundMonitor.CheckForegroundWindow() [auto-profile switching]
For each of the 16 slots:
| Slot type | Source array | Update call |
|---|---|---|
| All |
CombinedOutputStates[i], VibrationStates[i]
|
padVm.UpdateFromEngineState() |
| Custom Extended | CombinedExtendedRawStates[i] |
padVm.UpdateFromExtendedRawState() |
| MIDI | CombinedMidiRawStates[i] |
padVm.UpdateFromMidiRawState() |
| KB+M | CombinedKbmRawStates[i] |
Sets padVm.KbmOutputSnapshot
|
Per-device stick/trigger previews read either KBM pre-deadzone values (synthesized into a Gamepad struct) or the selected device's RawMappedState.
Two flags gate expensive per-frame work:
| Flag | When true |
|---|---|
IsDevicesPageVisible |
Calls UpdateDevicesRawState()
|
IsPadPageVisible |
Calls UpdateMappingLiveValues()
|
Both are set by MainWindow navigation.
Pushes engine statistics to DashboardViewModel: state key ("Running"/"Idle"/"Stopped"), localized status, PollingFrequency, and device counts (TotalDevices, OnlineDevices, MappedDevices) computed under UserDevices.SyncRoot lock. Calls RefreshSlotSummaryProperties() and RefreshNavItemConnectedCounts().
Updates all SlotSummary items on the dashboard with per-slot status (IsActive, DeviceName, MappedDeviceCount, ConnectedDeviceCount, IsVirtualControllerConnected, IsInitializing, IsEnabled, StatusText) and per-type numbering (e.g., "Xbox 1", "PlayStation 2").
Updates sidebar NavControllerItem.ConnectedDeviceCount and IsInitializing for power icon color logic.
Updates the raw input state display for the selected device:
- Finds
UserDevicefor the selectedDeviceRowViewModel. - On device change: rebuilds axis/button/POV collections via
devVm.RebuildRawStateCollections(). - Updates axes in-place (
NormalizedValue = Axis[i] / 65535.0), buttons, keyboard keys, POV hats, mouse motion/scroll, and gyro/accel (if supported).
Handles SelectedDevice changes when the engine is not running. Populates the detail panel from cached UserDevice capabilities so the layout is visible offline.
For the active Pad page: finds the selected device, parses each MappingItem.SourceDescriptor, reads the raw value from CustomInputState, and sets mapping.CurrentValueText.
Simplified Step 3 parser for display. Strips I/H prefixes, parses "Axis N", "Button N", "Slider N", "POV N" descriptors, and reads from the state arrays.
Primary runtime sync path. For each pad slot:
-
Always synced (even with no device selected):
-
SlotControllerTypes[i]frompadVm.OutputType - Extended config via
SyncExtendedConfigToSlot() - MIDI config via
_inputManager._midiConfigs[i]
-
-
Per-device sync (when a device is selected):
- Calls
SaveViewModelToPadSetting(padVm, instanceGuid, syncMappings: false) - Pushes deadzones (independent X/Y), anti-deadzones, linear, center offsets, max range (independent directions), trigger deadzones, force feedback gains, audio rumble settings
-
Mapping descriptors are NOT synced at 30 Hz to avoid a race condition.
ClearMappingDescriptors()creates a window where the polling thread sees empty mappings
- Calls
-
Audio bass detector lifecycle: detects when
AudioRumbleEnabledtoggles on any slot and callsSyncAudioBassDetector().
Writes all tuning parameters from ViewModel to PadSetting. When syncMappings is true (explicit save, preset change, device switch), also clears and rewrites all mapping descriptors.
Reverse direction: reads PadSetting and populates the PadViewModel (deadzones, sensitivity curves, max ranges, center offsets, triggers, force feedback, audio rumble, mapping descriptors).
private void OnSettingsPropertyChanged(object sender, PropertyChangedEventArgs e)Propagates SettingsViewModel changes to the engine at runtime:
| Property | Action |
|---|---|
PollingRateMs |
Sets _inputManager.PollingIntervalMs
|
EnableInputHiding |
Calls ApplyDeviceHiding() or RemoveDeviceHiding()
|
private void OnDashboardPropertyChanged(object sender, PropertyChangedEventArgs e)Propagates DashboardViewModel changes:
| Property | Action |
|---|---|
EnableDsuMotionServer |
Starts or stops DSU server |
DsuMotionServerPort |
Restarts DSU server if enabled |
EnableWebController |
Starts or stops web controller server |
WebControllerPort |
Restarts web controller server if enabled |
All fire on the polling thread and are marshalled to UI via Dispatcher.BeginInvoke.
| Handler | Action |
|---|---|
OnDevicesUpdated |
SyncDevicesList(), UpdatePadDeviceInfo(), ApplyDeviceHiding()
|
OnFrequencyUpdated |
No-op (frequency read on next UI tick) |
OnErrorOccurred |
Sets _mainVm.StatusText
|
Synchronizes DevicesViewModel.Devices with SettingsManager.UserDevices:
- Snapshots under lock.
- Updates existing rows, adds new ones (skips virtual/shadow devices).
- Removes stale or virtual rows.
- Sorts by name, then VID:PID.
- Calls
devVm.RefreshCounts().
Filters legacy and shadow virtual controllers from the Devices-page list (defense-in-depth; Step 1 already filters HIDMaestro upstream). Returns true when any of these match on an online device: name contains "ViGEm" or "Virtual Gamepad" (case-insensitive), device path lowercase contains "vigem" or "virtual", or the device has IsHidden = true. Offline devices always return false because virtual controllers only exist while the engine is running.
Maps UserDevice properties to the ViewModel row: name, VID/PID, online status, capabilities, device type, slot assignments, HidHide state, instance path.
Rebuilds each PadViewModel's MappedDevices from UserSettings.FindByPadIndex(). Handles multi-device slots, auto-selects first device, refreshes sidebar and dashboard.
Builds the input source dropdown for a pad slot's selected device. Uses Math.Max(CapButtonCount, RawButtonCount) to generate button entries, ensuring the full button list is available regardless of whether the device is in gamepad or raw joystick mode. When the device is offline, falls back to cached DeviceObjects and stored capability counts so the mapping UI remains functional without a live connection.
Called when ForceRawJoystickMode is toggled on a device. Rebuilds the input source dropdown and mapping descriptors for all pad slots using that device, reflecting the change in available raw vs. gamepad inputs.
When the user selects a different device in a pad slot's dropdown:
- Saves current ViewModel values to the previous device's PadSetting (skipped when re-adding the same device).
-
Loads the new device's PadSetting via
LoadPadSettingToViewModel(). - Populates input dropdown via
PopulateAvailableInputs(). - Updates the
_previousSelectedDevicetracker.
When mappings are rebuilt (OutputType or HIDMaestro profile change), reloads mapping descriptors from PadSetting without touching deadzone or force feedback settings.
Applies a source PadSetting to the selected device. Used by Paste and "Copy From".
Applies with cross-layout translation (e.g., Xbox to Extended mapping key conversion).
Flushes all active PadViewModel state to PadSettings. Call before reading PadSettings across slots (e.g., Copy From dialog).
Returns the PadSetting for the selected device after syncing ViewModel state.
Creates a snapshot array of MacroItem objects per slot and assigns it to _inputManager.MacroSnapshots[i]. The engine reads these atomically each cycle. Empty lists set the snapshot to null.
Starts recording button/axis/POV presses for a macro trigger combo. Captures axis baselines for delta detection.
Finalizes recording. Writes accumulated data to the MacroItem by trigger path:
| Path | Data written |
|---|---|
| InputDevice | Raw device buttons (TriggerRawButtons) + device GUID |
| Custom Extended | Numbered button words (TriggerCustomButtonWords) |
| OutputController | Xbox button bitmask (TriggerButtons) |
Also writes axis targets/directions and POV triggers.
Called each UI tick during recording. Reads state per TriggerSource:
| Source | Behavior |
|---|---|
| InputDevice | Scans raw buttons/POVs from mapped devices. First press locks _recordingDeviceGuid
|
| Numbered (custom Extended) | Accumulates from CombinedExtendedRawStates
|
| OutputController | Accumulates from CombinedOutputStates Xbox button bitmask |
Axis detection: 25% threshold, 3-cycle hold confirmation (same as RecorderService).
- Checks
Dashboard.EnableDsuMotionServerand engine existence. - Creates
DsuMotionServer, subscribes toStatusChanged. - Validates port (1024–65535; default 26760).
- Starts server. On success assigns to
_inputManager.DsuServer; on failure disposes.
- Clears
_inputManager.DsuServer. - Disposes server instance.
- Checks
Dashboard.EnableWebControllerand engine existence. - Creates
WebControllerServer, subscribes toStatusChanged,DeviceConnected,DeviceDisconnected. - Device connect/disconnect calls
_inputManager.RegisterExternalDevice()/UnregisterExternalDevice(). - Validates port (1024–65535; default 8080), starts server.
Unsubscribes from StatusChanged, disposes server, clears status and client count.
Called on engine start, slot changes, and during 30 Hz sync when AudioRumbleEnabled toggles. Starts the detector if any slot enables audio rumble. Stops it if none do.
Creates and starts AudioBassDetector. On success, assigns to _inputManager.AudioBassDetector; on failure, disposes.
Clears _inputManager.AudioBassDetector, disposes detector, zeros all pad level meters.
When _audioBassDetector != null, reads BassEnergy and pushes to padVm.AudioRumbleLevelMeter for each created slot with AudioRumbleEnabled.
Only acts if EnableInputHiding is on. Two mechanisms:
HidHide (driver-level):
- Builds whitelist (PadForge exe + user paths).
SyncWhitelist()adds/removes only PadForge-managed entries. - For each
UserDevicewithHidHideEnabled: convertsDevicePathto HID instance ID (fallback: VID/PID lookup for synthetic paths like "XInput#0"). Caches resolved IDs for offline pre-emptive blacklisting. -
HidHideController.SyncManagedDevices(desiredIds). Atomic diff-based sync. - Activates cloaking if any devices are blacklisted.
Input hooks (keyboard/mouse):
- For each device with
ConsumeInputEnabledand a slot assignment: parses "Button {index}" descriptors to collect VKey codes or mouse button IDs. - Creates/updates
InputHookManagerif inputs need suppressing. Otherwise stops and disposes it.
Calls HidHideController.RemoveManagedDevices() (best-effort), stops and disposes InputHookManager.
Converts Windows paths to DOS device paths. Only modifies PadForge-managed entries. Entries from HidHide Client or other tools are left untouched. Tracked via _managedWhitelistDosPaths.
Sets _inputManager.IsIdle based on whether any slot is created, enabled, and has a device assigned. Idle mode skips input/mapping/output and sleeps at ~20 Hz, reducing CPU to ~0%.
Captures current runtime state:
- Flushes all PadViewModel values to PadSettings.
- Collects
ProfileEntry(InstanceGuid, ProductGuid, MapTo, checksum) and deduplicatedPadSettingclones. - Captures
SlotCreated[],SlotEnabled[],SlotControllerTypes[],SlotProfileIds[](per-slot HIDMaestro profile slug), Extended/MIDI configs, DSU/web server settings.
Restores a profile:
-
Topology. Sets
SlotCreated[],SlotEnabled[],OutputType,ProfileId(per-slot HM profile slug), and unassigns devices from destroyed slots. The HM slug update gates Step 5's per-slot diff atInputManager.Step5.VirtualDevices.cs:599-614. Slots whose new slug matches the liveHMaestroVirtualController.ProfileIdstay live untouched. Slots whose slug differs are destroyed and recreated with the new identity. -
Device assignments (single-pass transition). Builds the desired final assignment map from
profile.Entriesfirst, then transitions eachUserSettingdirectly old → newMapTo(or → -1 for entries dropped from the new profile). The "find UserSetting" gate is "not yet consumed by a prior entry in this same apply pass," not the previous reset-MapTo-to-negative gate. This avoids the reset window where the polling thread could observeHasAnyDeviceMapped == falsefor surviving slots and fall into the immediate-destroy path atInputManager.Step5.VirtualDevices.cs:680-700. Slots whose mapping is unchanged across profiles transition with zero teardown. -
Extended/MIDI configs. Restores per-slot Extended config (
Customizetoggle, axis/trigger/POV/button counts, OEM-name override, product string) and MIDI config (channel, CC/note ranges, velocity). - Server settings. Sets DSU and web controller enable/port.
-
Rebuilds UI.
UpdatePadDeviceInfo(), reloads PadSettings, refreshes Devices page.
Called by ForegroundMonitorService when the foreground process matches a different profile. Skips if same profile already active. Saves outgoing state via SaveActiveProfileState(), then applies the target profile (or reverts to default if profileId is null).
Snapshots current state. Default profile: updates _defaultProfileSnapshot and PendingDefaultSnapshot. Named profile: updates stored data in SettingsManager.Profiles.
Refreshes the default profile snapshot from current state. Called after saving when no profile is active.
Applies _defaultProfileSnapshot to revert to the pre-profile state.
The reorder model rests on five rules:
- Pad indices are data identity. A pad's mappings, profile, devices, settings, and dirty flags live at its pad index and never move on reorder.
-
Visual position is the kernel-slot anchor. Within an HM-backed group (Xbox / PlayStation / Extended), the VC at visual position V holds kernel slot V.
SlotOrders[group][V] = padIndexsays which pad's data the VC at slot V is serving. -
Reorder repoints, not rebuilds.
SwapSlots/MoveSlotmutateSlotOrders(visual order). The kernel VC at each visual position stays put. The pad-index pointer in_virtualControllers[]moves so the data at the new pad-at-position-V feeds into V's kernel slot. -
Same-profile reorders are zero-flicker. Pointer swap in
_virtualControllers[]plusFeedbackPadIndexupdate on the moved VC. Per-VC state arrays move with the VC. - Different-profile positions destroy + recreate. Only the specific positions whose profile changed. Matching positions in the same reorder still pointer-swap.
Per-pad state (_slotInactiveCounter, _createFailed, _hmInactivityFired, _slotInitializing, _pendingDisposeTask, _pendingConnectTask) describes the pad's lifecycle and stays at the pad index. Per-VC state (_loggedFirstSubmit, _extendedAppliedProductString, _extendedAppliedLayout, _oemOverrideClaimedVidPid, _lastAppliedOemLabel) moves with the VC.
Swaps two slots' visual positions within their (shared) group. Snapshots the pre-swap order, mutates SlotOrders via SwapWithinGroup, then calls RebuildKernelOrderAfterReorder(groupType, oldOrder). Cross-group calls are rejected. Refreshes UI after.
Moves a slot from its current visual position to a new visual position within the same group. Snapshots the pre-move order, mutates SlotOrders via MoveWithinGroup, then calls RebuildKernelOrderAfterReorder(groupType, oldOrder).
RebuildKernelOrderAfterReorder(VirtualControllerType groupType, IReadOnlyList<int> oldOrder) (private)
Thin delegator. Reads the new order from SettingsManager.SlotOrders.GetOrderFor(groupType) and calls _inputManager.RerouteVirtualControllersForReorder(groupType, oldOrder, newOrder). Non-HM groups (KBM, MIDI) are filtered inside the engine method since their slot order is not tied to a kernel-side index allocation.
InputManager.RerouteVirtualControllersForReorder(VirtualControllerType groupType, IReadOnlyList<int> oldOrder, IReadOnlyList<int> newOrder) (public, engine)
Walks oldOrder against newOrder position by position and decides per visual position whether to reuse the existing VC at that kernel slot or destroy it. Three-step implementation:
-
Decide per position. For each visual position V, compare the profile of the VC at
oldOrder[V]againstSlotProfileIds[newOrder[V]]. Same profile: the VC at V is reused. Different profile: the old VC is queued for destruction. While walking, snapshot the per-VC state at eacholdPadso it can travel with the VC. -
Destroy mismatched VCs. Each goes through
DestroyVirtualController(oldPad, asyncDispose: true), which releases OEM override claims and queues HIDMaestro teardown to the thread pool. Per-pad state at these old pads is cleared. -
Re-route reused VCs. For each reused VC, write the VC pointer plus its per-VC state snapshot into the destination pad's slot in the engine arrays, and update
FeedbackPadIndexso vibration callbacks land in the rightVibrationStates[]entry. Per-VC state cleared at the old pad if it differs from the new pad.
Same-profile cycles (Example: insert a Profile-A slot at the top of an all-Profile-A group) collapse to a pure pointer rotation across _virtualControllers[] with no kernel teardown. Zero-flicker for the game side. Different-profile positions go through the regular destroy + recreate path; Pass 2's visual-order gate plus ApplyAscendingIndexPreemption recreate them with the new pad's profile, taking the lowest free kernel slot (which is V, because surviving VCs at positions < V keep theirs). The swap-only path does not engage Pass 2's preemption.
Non-HM group types are rejected at the entry. Cross-group moves do not route through here at all. MoveSlotToGroupTail changes SlotControllerTypes[padIndex], which Pass 1 detects as a type change and destroys the old-group VC; the new group's ordinary creation logic spins up the new VC at the tail.
This replaced the v2-era ShouldRebuildKernelOrder predicate and the live-subsequence walk that destroyed every live VC at and below the lowest changed position. Reorders now make per-position reuse decisions, so a same-profile rotation involves zero VC destroys.
Groups slots by type order: Xbox, PlayStation, Extended, KB+M, MIDI. Within a group, drag-and-drop reorder is honored via SettingsManager.SlotOrders. Uses bubble sort with SwapSlotData (data-only, no VC destruction). Returns true if reordering occurred.
Sets vibration to 32768 on left/right motors. Optional device GUID filter. Clears after 500 ms via a one-shot DispatcherTimer.
// Overload for selective motors
public void SendTestRumble(int padIndex, Guid? deviceGuid, bool left, bool right)When deviceGuid is non-null, the call also stores the GUID in _inputManager.TestRumbleTargetGuid[padIndex]. The UserEffectsDispatcher.TestRumbleTargetGuidProvider callback (wired in Start()) reads that value so per-device effects on Impulse Triggers / Force Feedback / Adaptive Triggers / Lighting tabs only fire on the selected pad. The gate is target == Guid.Empty || ud.InstanceGuid == target. See feedback_per_device_test_isolation.md in project memory.
InputService.ToggleVCsDisabled is an Action set by MainWindow so the engine can fan out a profile-shortcut combo into DeviceService.SetSlotEnabled calls for every created slot. The flow:
- Engine thread observes
_inputManager.PendingToggleVCsDisabled(set by a profile-shortcut activator). - Marshals
ToggleVCsDisabled?.Invoke()to the UI thread inside the polling cycle. - UI handler reads each
SlotCreated[i]; if anySlotEnabled[i]is true, disables them all, else enables them all. -
MainViewModel.RefreshNavControllerItems()updates the sidebar;ProfileSwitchOverlayshows a Fluent green / red flyout.
| Method | Signature | Description |
|---|---|---|
Start |
void Start() |
Creates engine, starts all subsystems, begins UI timer |
Stop |
void Stop() |
Stops engine and all subsystems |
Dispose |
void Dispose() |
Calls Stop() for cleanup |
RefreshSlotSummaryProperties |
void RefreshSlotSummaryProperties(IEnumerable<UserDevice> devices = null) |
Updates dashboard slot summary cards |
RefreshDeviceList |
void RefreshDeviceList() |
Full re-sync of device list UI |
UpdatePadDeviceInfo |
void UpdatePadDeviceInfo() |
Refreshes PadViewModel device info for all pads |
ApplyDeviceHiding |
void ApplyDeviceHiding() |
Applies HidHide + input hooks based on settings |
RemoveDeviceHiding |
void RemoveDeviceHiding() |
Removes all device hiding |
SendTestRumble |
void SendTestRumble(int padIndex, Guid? deviceGuid) |
Sends brief test rumble |
SendTestRumble |
void SendTestRumble(int padIndex, Guid? deviceGuid, bool left, bool right) |
Sends selective test rumble |
ApplyPadSettingToCurrentDevice |
void ApplyPadSettingToCurrentDevice(int padIndex, PadSetting source) |
Applies copied PadSetting |
ApplyPadSettingToCurrentDeviceTranslated |
void ApplyPadSettingToCurrentDeviceTranslated(int padIndex, PadSetting source, VirtualControllerType sourceType, bool sourceIsCustomExtended, VirtualControllerType targetType, bool targetIsCustomExtended) |
Applies with cross-layout translation |
FlushAllPadViewModels |
void FlushAllPadViewModels() |
Saves all ViewModel state to PadSettings |
GetCurrentPadSetting |
PadSetting GetCurrentPadSetting(int padIndex) |
Gets PadSetting for selected device |
StartMacroTriggerRecording |
void StartMacroTriggerRecording(MacroItem macro, int padIndex) |
Starts macro trigger recording |
StopMacroTriggerRecording |
void StopMacroTriggerRecording() |
Stops macro trigger recording |
SnapshotCurrentProfile |
ProfileData SnapshotCurrentProfile() |
Captures current state as profile |
ApplyProfile |
void ApplyProfile(ProfileData profile) |
Loads a profile into runtime state |
SaveActiveProfileState |
void SaveActiveProfileState() |
Saves current state into active profile |
RefreshDefaultSnapshot |
void RefreshDefaultSnapshot() |
Refreshes default profile from current state |
ApplyDefaultProfile |
void ApplyDefaultProfile() |
Reverts to default profile |
RefreshProfileTopology |
void RefreshProfileTopology() |
Refreshes active profile topology label |
SwapSlots |
void SwapSlots(int padIndexA, int padIndexB) |
Swaps two controller slots |
MoveSlot |
void MoveSlot(int sourcePadIndex, int targetVisualPosition) |
Moves slot to visual position |
EnsureTypeGroupOrder |
bool EnsureTypeGroupOrder(bool silent = false) |
Groups slots by type |
InputService exposes no custom events. All UI updates flow through ViewModel properties and InputManager's marshalled events.
Properties used as communication channels:
| Property | Type | Description |
|---|---|---|
Engine |
InputManager (get-only) |
Access to underlying InputManager |
IsDevicesPageVisible |
bool (get/set) |
Gates Devices page raw state updates |
IsPadPageVisible |
bool (get/set) |
Gates mapping live value updates |
SettingsService |
SettingsService (set-only) |
For triggering saves on cache updates |
ToggleMainWindow |
Action (get/set) |
Callback to show/hide the main window. Set by MainWindow at startup. |
The ToggleMainWindow property is an Action delegate set by MainWindow during initialization. It handles three visibility states:
-
Hidden (system tray). Calls
RestoreFromTray()+ForceToForeground(). -
Minimized or inactive. Restores
WindowStateand callsForceToForeground(). -
Foreground and visible. Minimizes (or hides to tray if
MinimizeToTrayenabled).
The engine thread sets InputManager.PendingToggleWindow = true when a global macro with SwitchProfileMode.ToggleWindow fires. The UI thread consumes this volatile flag inside UiTimer_Tick, immediately after pending profile switch handling:
if (_inputManager.PendingToggleWindow)
{
_inputManager.PendingToggleWindow = false;
ToggleMainWindow?.Invoke();
}ShowProfileSwitchOverlay(string profileId) creates (or reuses) a ProfileSwitchOverlay window and wires two callbacks that the overlay polls at ~30 Hz to track virtual controller initialization:
| Callback | Signature | Purpose |
|---|---|---|
CheckAllSlotsInitState |
Func<(bool anyInitializing, bool allReady)> |
Returns whether any created+enabled slots are still initializing, and whether all are ready. Checks each VC's lifecycle state. |
CheckAnyControllerOffline |
Func<bool> |
Returns true if any created+enabled slot has no online physical devices assigned. Used to show a warning after the "Active" state. |
CheckAllSlotsInitState() iterates all 16 slots. If SlotCreated[i] && SlotEnabled[i], it checks whether the virtual controller exists and is connected. CheckAnyControllerOffline() similarly iterates slots and checks whether any assigned UserSetting references a device that is offline.
Shortcut combo recording is implemented in ProfilesPage.xaml.cs, not InputService, because it requires direct access to the XAML ItemsControl and per-row ProfileShortcutViewModel instances.
ShortcutLearn_Click(object sender, RoutedEventArgs e). Starts a 5-second recording window:
- Cancels any in-progress recording on another shortcut row.
- Snapshots axis baselines from all online devices (
_recordAxisBaselines). - Sets
InputService.SetSuppressGlobalMacros(true)to prevent the combo from firing during recording. - Creates a 33 ms
DispatcherTimer(_recordTimer).
RecordTimer_Tick(object sender, EventArgs e). Fires at ~30 Hz during recording:
- Updates the countdown display via
RecordingCountdown. - Scans all online devices for pressed buttons and axis deflections exceeding
AxisRecordDeltaThreshold(0.25). - Builds
TriggerButtonEntry[]with per-button device tracking (DeviceInstanceGuid,DeviceProductGuid,IsAxis,AxisIndex,AxisThreshold,AxisDirection). - Temporarily sets entries on the ViewModel for live display.
- Auto-stops after
RecordTimeoutSeconds(5 seconds).
StopRecording(). Finalizes:
- Stops
_recordTimer. - If valid entries were captured, calls
_recordingShortcut.SetLearnedButtons(entries). - Otherwise calls
CancelRecording()on the ViewModel. - Clears
_recordAxisBaselinesand callsSetSuppressGlobalMacros(false).
File: PadForge.App/Services/SettingsService.cs
Loads and saves PadForge settings to XML. Handles bidirectional sync between SettingsManager data and WPF ViewModels.
public SettingsService(MainViewModel mainVm)Stores reference to MainViewModel.
- Ensures
UserDevicesandUserSettingscollections exist. - Finds settings file via
FindSettingsFile(). - Loads if found. Otherwise initializes with defaults.
- Sets
SettingsFilePath, clears dirty flag.
Search order (all relative to AppDomain.CurrentDomain.BaseDirectory):
-
PadForge.xml(primary) -
Settings.xml(fallback) - If neither exists, creates
PadForge.xml.
- Deserializes
SettingsFileDatafrom XML. - Populates
UserDevicesandUserSettingsunderSyncRootlocks. - PadSetting linking: finds PadSetting by checksum and clones it. Cloning is critical. Without it, devices sharing a checksum would share one object.
- Purges orphaned UserSettings (
MapTo == -1). - Calls
LoadAppSettings(),LoadPadSettings(),LoadMacros(),LoadProfiles().
Pushes to SettingsViewModel: AutoStartEngine, MinimizeToTray, StartMinimized, StartAtLogin, EnablePollingOnFocusLoss, PollingRateMs, theme, language, input hiding, auto-profile switching, slot types, Extended/MIDI configs, DSU/web server settings.
Critical load order: SlotCreated[] and SlotEnabled[] must load BEFORE OutputType, because OutputType fires PropertyChanged which reads SlotCreated.
For each slot (first device only), loads all tuning parameters into PadViewModel: deadzones, sensitivity curves, max ranges, center offsets, triggers, force feedback, audio rumble, Extended HID custom configs, and mapping descriptors. Per-mapping deadzones are loaded with a default of 50 (centered, no effect) for mappings that lack a stored value.
Rebuilds each PadViewModel's macro list from MacroData[], grouped by pad index.
SettingsService doesn't own the live custom-gesture list. That lives on InputService._activeTouchpadGestures. Two callback hooks bridge the two services without a reverse reference:
-
TouchpadGesturesProvider(Func<TouchpadCustomGesture[]>): SettingsService calls this at save time to get the current gestures. Returns null when there are none. -
TouchpadGesturesApplier(Action<TouchpadCustomGesture[]>): SettingsService calls this after a load to seed InputService's working list.
Startup order matters: LoadFromFile runs before StartEngine wires the applier, so the load path stashes loaded gestures in _pendingTouchpadGesturesToApply. The applier-setter property auto-flushes the pending slot on first assignment.
Calls SaveToFile(_settingsFilePath).
-
UpdatePadSettingsFromViewModels()pushes all ViewModel values to PadSettings. - Flushes Extended/MIDI/KBM mapping dictionaries to serializable arrays, recomputes checksums.
-
FlushMappingDeadZones(). Collects per-mapping deadzone values from all PadViewModels and writes them into the corresponding PadSetting objects before serialization. - Updates active profile snapshot via
UpdateActiveProfileSnapshot(). - Collects devices, user settings, deduplicated pad settings (under locks), app settings, macros, profiles.
- Serializes
SettingsFileDatato XML, clears dirty flag.
Note: When a named profile is active, BuildAppSettings() stores the default profile's slot state (from PendingDefaultSnapshot), not the current runtime state. This prevents the named profile's topology from contaminating the default.
Sets IsDirty = true, starts a 250 ms debounce DispatcherTimer (restarted if already running). On tick: calls Save(), raises AutoSaved. The debounce batches rapid changes (e.g., slider drags) into a single save.
Clears all SettingsManager collections, resets all ViewModels to defaults, clears profiles, marks dirty.
Reloads from disk, discarding unsaved changes.
- Adds the built-in Default profile at the top.
- Adds each saved profile with topology counts.
- If a named profile was active at shutdown, restores its slot config and captures the default snapshot from XML (
PendingDefaultSnapshot).
Called during Save. If a named profile is active, updates its stored snapshot from current state (entries, PadSettings, topology, server settings).
Counts Xbox/PlayStation/Extended/MIDI/KBM slots and sets topology label (e.g., "2x Xbox, 1x PlayStation").
| Method | Signature | Description |
|---|---|---|
Initialize |
void Initialize() |
Finds settings file, loads, initializes collections |
LoadFromFile |
void LoadFromFile(string filePath) |
Loads settings from XML |
Save |
void Save() |
Saves to active settings file |
SaveToFile |
void SaveToFile(string filePath) |
Saves to specified XML file |
MarkDirty |
void MarkDirty() |
Marks dirty, schedules 250ms autosave |
Reload |
void Reload() |
Reloads from disk |
ResetToDefaults |
void ResetToDefaults() |
Resets all settings to defaults |
| Event | Signature | Description |
|---|---|---|
AutoSaved |
event EventHandler AutoSaved |
Raised after autosave completes |
Properties:
| Property | Type | Description |
|---|---|---|
SettingsFilePath |
string (get) |
Full path to active settings file |
IsDirty |
bool (get) |
Whether unsaved changes exist |
File: PadForge.App/Services/DeviceService.cs
Handles UI-triggered device management: assign/unassign, hide/show, create/delete virtual controller slots. Bridges DevicesViewModel commands to SettingsManager and SettingsService.
public DeviceService(MainViewModel mainVm, SettingsService settingsService)Stores MainViewModel and SettingsService references.
Subscribes to DevicesViewModel events:
| Event | Handler |
|---|---|
AssignToSlotRequested |
OnAssignToSlot |
ToggleSlotRequested |
OnToggleSlot |
HideDeviceRequested |
OnHideDevice |
RemoveDeviceRequested |
OnRemoveDevice |
DeviceHidingChanged |
OnDeviceHidingChanged |
Unsubscribes from all DevicesViewModel events.
Assigns the selected device to a slot:
- Auto-creates the slot if needed.
-
SettingsManager.AssignDeviceToSlot(), populatesProductGuid. - Creates default
PadSettingif none exists. -
AutoEnableHidingDefaults()for newly assigned devices. - Marks dirty, raises
DeviceAssignmentChanged,DeviceHidingStateChanged,NavigateToSlotRequested.
Public version for drag-and-drop. Same logic as OnAssignToSlot but takes a GUID directly.
Toggles device assignment for a slot (multi-slot support). If unassigning leaves no remaining slots, auto-disables hiding.
Removes all slot assignments for a device.
Creates the next available slot:
- Sets
OutputTypebeforeSlotCreated(order matters for sidebar rebuild). - Sets
ProfileId = GetDefaultProfileId(type)so the profile picker shows a selection immediately. For Xbox slots the default comes fromXboxProfiles.DefaultXboxProfileId. For Extended this is the Custom "PadForge Game Controller" profile. - Returns slot index (0–15) or -1 if full.
Clears SlotCreated[slotIndex], calls padVm.ResetAllSettings() to prevent stale leaks, removes all UserSettings mapped to this slot.
Sets SettingsManager.SlotEnabled[slotIndex].
Marks a device as hidden in SettingsManager and ViewModel.
Removes a device and all associated settings. The virtual controller slot persists empty.
Handles HidHide/ConsumeInput/ForceRawJoystickMode toggles. Writes state to UserDevice, marks dirty, raises DeviceHidingStateChanged.
Sets default hiding for newly assigned devices. Gamepads: auto-enables HidHide (if driver available). Keyboards/mice: does not auto-enable (blocking the only keyboard/mouse would lock out Windows).
| Method | Signature | Description |
|---|---|---|
WireEvents |
void WireEvents() |
Subscribes to DevicesViewModel events |
UnwireEvents |
void UnwireEvents() |
Unsubscribes from events |
AssignDeviceToSlot |
void AssignDeviceToSlot(Guid instanceGuid, int slotIndex) |
Public assignment for drag-and-drop |
UnassignDevice |
void UnassignDevice(Guid instanceGuid) |
Removes all slot assignments |
CreateSlot |
int CreateSlot(VirtualControllerType type = Xbox) |
Creates next available slot |
DeleteSlot |
void DeleteSlot(int slotIndex) |
Deletes a slot and unassigns devices |
SetSlotEnabled |
void SetSlotEnabled(int slotIndex, bool enabled) |
Enables/disables a slot |
| Event | Signature | Description |
|---|---|---|
DeviceAssignmentChanged |
event EventHandler DeviceAssignmentChanged |
Fired after assign/unassign. MainWindow refreshes PadViewModel device info |
NavigateToSlotRequested |
event EventHandler<int> NavigateToSlotRequested |
Fired after assignment. MainWindow navigates to the assigned slot's page |
DeviceHidingStateChanged |
event EventHandler DeviceHidingStateChanged |
Fired when hiding toggles change. InputService re-applies device hiding |
File: PadForge.App/Services/RecorderService.cs
Implements: IDisposable
Handles input recording for mapping assignment. When the user clicks "Record", captures current state as a baseline, polls at 30 Hz for changes, and writes the detected input descriptor to the MappingItem.
public RecorderService(MainViewModel mainVm)Stores reference to MainViewModel.
User clicks Record
|
StartRecording(mapping, padIndex, deviceGuid)
|
v
Capture baseline state (clone of CustomInputState)
|
v
Start 30Hz DispatcherTimer (PollTick)
|
v [each tick]
PollTick:
1. Check timeout (10 seconds)
2. Read current state (clone)
3. Wait-for-release phase (if neutralizeBaseline)
4. Check buttons (instant detection)
5. Check POV hats (instant detection)
6. Check axes (3-cycle hold confirmation)
|
v [on detection]
CompleteRecording:
1. Build descriptor string ("Button 0", "Axis 1", "POV 0 Up")
2. Auto-detect inversion based on movement direction + target type
3. Call mapping.LoadDescriptor(descriptor)
4. Raise RecordingCompleted event
StartRecording(MappingItem, int padIndex, Guid deviceGuid, bool neutralizeBaseline, bool negRecording) (public)
Cancels any existing recording, captures baseline CustomInputState, sets mapping.IsRecording = true, starts 30 Hz timer.
-
neutralizeBaseline: waits for all buttons/POVs to return to neutral before detecting (for auto-prompt follow-ups). -
negRecording: records the negative direction of a bidirectional axis.
Stops the timer, clears all recording state, sets IsRecording = false.
| Input type | Detection | Details |
|---|---|---|
| Buttons | Instant | Any button transitioning from unpressed to pressed |
| POV hats | Instant | Any POV transitioning from centered (-1) to a direction (8 sectors, 45 degrees each) |
| Axes | 3-cycle hold | Threshold: 16384 units (~25% of 65535 range). Largest absolute delta wins. Mouse exception: instant accept (deltas return to center) |
Auto-inversion: ShouldAutoInvert() applies the "I" prefix based on target type and direction:
| Target | Inverts when |
|---|---|
| Stick axes | User pushed wrong direction for target |
| Trigger axes | Axis value decreased (reverse polarity) |
| KBM axes | Never (screen convention is correct) |
| Other | User pushed negative |
Constants:
| Constant | Value | Description |
|---|---|---|
PollIntervalMs |
33 | ~30 Hz poll rate |
TimeoutSeconds |
10 | Recording auto-cancels after this |
AxisThreshold |
16384 | ~25% of full range |
AxisHoldCycles |
3 | Cycles axis must be held |
| Method | Signature | Description |
|---|---|---|
StartRecording |
void StartRecording(MappingItem mapping, int padIndex, Guid deviceGuid, bool neutralizeBaseline = false, bool negRecording = false) |
Starts input recording |
CancelRecording |
void CancelRecording() |
Cancels without assigning |
Dispose |
void Dispose() |
Cancels recording, disposes resources |
Properties:
| Property | Type | Description |
|---|---|---|
IsRecording |
bool (get) |
True when recording is active |
| Event | Signature | Description |
|---|---|---|
RecordingCompleted |
event EventHandler<RecordingResult> RecordingCompleted |
Raised on successful detection |
RecordingTimedOut |
event EventHandler RecordingTimedOut |
Raised after 10 second timeout |
RecordingResult fields: Mapping, PadIndex, Descriptor, Type, Index, PovDirection.
File: PadForge.App/Services/ForegroundMonitorService.cs
Monitors the foreground window and fires an event when the foreground process matches a profile's executable list. Not a standalone timer. Called at 30 Hz from InputService's UI timer tick.
Called at 30 Hz by UiTimer_Tick:
- Bails if
EnableAutoProfileSwitchingis false or no profiles exist. - Gets foreground window handle via
GetForegroundWindow(), then process ID andMainModule.FileName. - Skips if exe path unchanged (
_lastExePathdeduplication). - Matches against all profiles'
ExecutableNames(pipe-separated full paths, case-insensitive). - Fires
ProfileSwitchRequiredonly when the matched profile changes (_lastMatchedProfileId). Null signals reversion to default.
| Method | Signature | Description |
|---|---|---|
CheckForegroundWindow |
void CheckForegroundWindow() |
Polls foreground window and fires event on profile change |
| Event | Signature | Description |
|---|---|---|
ProfileSwitchRequired |
event Action<string> ProfileSwitchRequired |
Fired with profile ID (or null for default) when foreground process matches a different profile |
File: PadForge.App/MainWindow.xaml.cs
MainWindow owns the service instances and wires them to ViewModels. Two notable behaviors:
SyncBarBackgrounds() pixel-samples the current theme's background brush at runtime to match the sidebar and app branding bar backgrounds. Re-invoked on theme changes via the ThemeManager.Current.ActualApplicationThemeChanged handler, ensuring the bars stay consistent when the user switches between light and dark themes.
The "Add Controller" popup auto-dismisses on navigation, window move, window resize, and window deactivation. This prevents the popup from floating over stale content when the user interacts with other parts of the application.
App.OnStartup
|-- MainWindow constructor
| |-- Creates MainViewModel, SettingsService, InputService, DeviceService, RecorderService
| |-- SettingsService.Initialize() [loads XML into SettingsManager]
| |-- DeviceService.WireEvents() [subscribes to DevicesViewModel events]
| |-- InputService.SettingsService = ss [for save triggers]
| |-- InputService.Start() [creates engine, starts all subsystems]
| | |-- InputManager.Start() [launches polling thread]
| | |-- StartDsuServerIfEnabled()
| | |-- StartWebServerIfEnabled()
| | |-- SyncAudioBassDetector()
| | |-- ApplyDeviceHiding()
| | |-- UI timer starts (30Hz)
MainWindow.OnClosing
|-- InputService.Stop()
| |-- UI timer stops
| |-- Unsubscribe all events
| |-- StopDsuServer()
| |-- StopWebServer()
| |-- StopAudioBassDetector()
| |-- RemoveDeviceHiding()
| |-- InputManager.Stop() + Dispose()
| |-- Tear down all HM virtuals via HMContext.Dispose()
|-- SettingsService.Save() [final save]
|-- DeviceService.UnwireEvents()
|-- RecorderService.Dispose()
InputManager.UpdateDevices() [polling thread, every 2s]
|-- SDL enumerates devices
|-- DevicesUpdated event fires
|-- Dispatcher.BeginInvoke: [UI thread]
|-- SyncDevicesList()
|-- UpdatePadDeviceInfo()
|-- ApplyDeviceHiding() [blacklist newly connected devices]
User drags slider on Pad page
|-- PadViewModel property updates (data binding)
|-- [next 30Hz tick] SyncViewModelToPadSettings()
| |-- SaveViewModelToPadSetting(syncMappings: false)
| | |-- PadSetting properties updated (string refs, atomic)
| | |-- Polling thread reads new values next cycle
[30Hz tick] ForegroundMonitor.CheckForegroundWindow()
|-- Detects new foreground matches different profile
|-- ProfileSwitchRequired event fires
|-- InputService.OnProfileSwitchRequired(profileId)
|-- SaveActiveProfileState() [snapshot outgoing profile]
|-- ApplyProfile(target) [load incoming profile]
| |-- Set SlotCreated/Enabled/OutputType
| |-- Reset all MapTo = -1, apply profile entries
| |-- Apply Extended/MIDI configs
| |-- Apply DSU/Web server settings
| |-- UpdatePadDeviceInfo()
| |-- Reload PadSettings into ViewModels
User clicks Record button
|-- MainWindow calls RecorderService.StartRecording(mapping, padIndex, deviceGuid)
|-- [30Hz timer] PollTick detects input change
|-- CompleteRecording(type, index, direction)
|-- RecordingCompleted event fires
|-- MainWindow receives result, optionally prompts for next mapping
-
Architecture Overview: Solution structure, threading model,
SettingsManagervsSettingsService -
Input Pipeline:
InputManagerpolling loop driven byInputService -
Settings and Serialization:
SettingsServiceXML persistence,PadSettingdata model -
ViewModels:
PadViewModel,DashboardViewModelconsumed by service event handlers -
XAML Views:
MainWindow.xaml.cswires services to ViewModels -
Engine Library:
Gamepad,CustomInputState,UserDevice,UserSetting -
DSU Protocol Implementation:
DsuMotionServerlifecycle managed byInputService