public bool HandleEvent(MidiInMessageEventArgs e) { if (!IsHandling()) { SetHandling(true); //if loaded inactive, search again if (!assigned && identifier != null && !identifier.Equals("")) { assignment = parent.audioDevices.FindMixerSession(identifier); if (assignment != null) { assigned = true; } } // Fader match if (assigned && Match(faderNumber, e.MidiEvent, faderDef.faderCode, faderDef.faderOffset, faderDef.faderChannelOverride)) { if (assignment.sessionType == SessionType.Application) { MixerSession newAssignment = assignment.devices.FindMixerSession(assignment.sessionIdentifier); //update list for re-routered app, but only overrides if (newAssignment == null) //if there is new assignments, otherwise, there is no more a inactive { //MixerSession to hold the label SetRecordLight(true); return(true); } assignment = newAssignment; } if (faderDef.delta) { float curVol; var val = GetValue(e.MidiEvent); if (val > faderDef.range / 2) { curVol = assignment.ChangeVolume((faderDef.range - val) / faderDef.range); } else { curVol = assignment.ChangeVolume(val / faderDef.range); } parent.SetVolumeIndicator(faderNumber, curVol); } else { assignment.SetVolume(GetValue(e.MidiEvent) / faderDef.range); } if (assignment.IsDead()) { SetRecordLight(true); } return(true); } // Select match if (Match(faderNumber, e.MidiEvent, faderDef.selectCode, faderDef.selectOffset, faderDef.selectChannelOverride)) { if (GetValue(e.MidiEvent) != 127) // Only on button-down { return(true); } Console.WriteLine($@"Attempting to assign current window to fader {faderNumber}"); if (assigned) { Unassign(); parent.SaveAssignments(); } else { var pid = WindowTools.GetForegroundPID(); var mixerSession = parent.audioDevices.FindMixerSession(pid); if (mixerSession != null) { Assign(mixerSession); parent.SaveAssignments(); } else { Console.WriteLine($@"MixerSession not found for pid {pid}"); } } return(true); } // Mute match if (assigned && Match(faderNumber, e.MidiEvent, faderDef.muteCode, faderDef.muteOffset, faderDef.muteChannelOverride)) { if (GetValue(e.MidiEvent) != 127) // Only on button-down { return(true); } SetMuteLight(assignment.ToggleMute()); if (assignment.IsDead()) { SetRecordLight(true); } return(true); } // Record match if (assigned && Match(faderNumber, e.MidiEvent, faderDef.recordCode, faderDef.recordOffset, faderDef.recordChannelOverride)) { if (GetValue(e.MidiEvent) != 127) // Only on button-down { return(true); } if (WindowTools.IsProcessByNameRunning(applicationName)) { SetRecordLight(false); } else { WindowTools.StartApplication(applicationPath); } return(true); } } return(false); }
public bool HandleEvent(MidiInMessageEventArgs e) { if (!IsHandling()) { SetHandling(true); //if loaded inactive, search again if (!assigned && identifier != null && !identifier.Equals("")) { assignment = parent.audioDevices.FindMixerSession(identifier); if (assignment != null) { assigned = true; } } // Fader match if (assigned && Match(faderNumber, e.MidiEvent, faderDef.faderCode, faderDef.faderOffset, faderDef.faderChannelOverride)) { if (assignment.sessionType == SessionType.Application) { MixerSession newAssignment = assignment.devices.FindMixerSession(assignment.sessionIdentifier); //update list for re-routered app, but only overrides if (newAssignment == null) //if there is new assignments, otherwise, there is no more a inactive { //MixerSession to hold the label SetRecordLight(true); return(true); } assignment = newAssignment; } float newVol; if (faderDef.delta) { var val = GetValue(e.MidiEvent); var volNow = assignment.GetVolume(); var nearestStep = steps.Select((x, i) => new { Index = i, Distance = Math.Abs(volNow - x) }).OrderBy(x => x.Distance).First().Index; int nextStepIndex; var volumeGoingDown = val > faderDef.range / 2; if (volumeGoingDown) { nextStepIndex = Math.Max(nearestStep - 1, 0); } else { nextStepIndex = Math.Min(nearestStep + 1, steps.Length - 1); } newVol = steps[nextStepIndex]; assignment.SetVolume(newVol); } else { newVol = getVolFromStage(GetValue(e.MidiEvent)); assignment.SetVolume(newVol); } if (assignment.IsDead()) { SetRecordLight(true); return(true); } List <Fader> fadersToAffect = GetMatchingFaders(); fadersToAffect.ForEach(fader => fader.parent.SetVolumeIndicator(fader.faderNumber, newVol)); return(true); } // Select match if (Match(faderNumber, e.MidiEvent, faderDef.selectCode, faderDef.selectOffset, faderDef.selectChannelOverride)) { if (GetValue(e.MidiEvent) != 127) // Only on button-down { return(true); } Console.WriteLine($@"Attempting to assign current window to fader {faderNumber}"); if (assigned) { Unassign(); parent.SaveAssignments(); } else { var pid = WindowTools.GetForegroundPID(); var mixerSession = parent.audioDevices.FindMixerSession(pid); if (mixerSession != null) { Assign(mixerSession); parent.SaveAssignments(); } else { Console.WriteLine($@"MixerSession not found for pid {pid}"); } } return(true); } // Mute match if (assigned && Match(faderNumber, e.MidiEvent, faderDef.muteCode, faderDef.muteOffset, faderDef.muteChannelOverride)) { if (GetValue(e.MidiEvent) != 127) // Only on button-down { return(true); } var muteStatus = assignment.ToggleMute(); SetMuteLight(muteStatus); if (assignment.IsDead()) { SetRecordLight(true); return(true); } List <Fader> fadersToAffect = GetMatchingFaders(); fadersToAffect.ForEach(fader => fader.SetMuteLight(muteStatus)); return(true); } // Record match if ( assigned && applicationPath != null && Match(faderNumber, e.MidiEvent, faderDef.recordCode, faderDef.recordOffset, faderDef.recordChannelOverride) ) { if (GetValue(e.MidiEvent) != 127) // Only on button-down { return(true); } if (WindowTools.IsProcessByNameRunning(applicationName)) { SetRecordLight(false); } else { WindowTools.StartApplication(applicationPath); } return(true); } } return(false); }
public bool HandleEvent(MidiInMessageEventArgs e) { // Fader match if (assigned && Match(faderNumber, e.MidiEvent, faderDef.faderCode, faderDef.faderOffset, faderDef.faderChannelOverride)) { if (faderDef.delta) { float curVol; var val = GetValue(e.MidiEvent); if (val > faderDef.range / 2) { curVol = assignment.ChangeVolume((faderDef.range - val) / faderDef.range); } else { curVol = assignment.ChangeVolume(val / faderDef.range); } parent.SetVolumeIndicator(faderNumber, curVol); } else { assignment.SetVolume(GetValue(e.MidiEvent) / faderDef.range); } if (assignment.IsDead()) { SetRecordLight(true); } return(true); } // Select match if (Match(faderNumber, e.MidiEvent, faderDef.selectCode, faderDef.selectOffset, faderDef.selectChannelOverride)) { if (GetValue(e.MidiEvent) != 127) // Only on button-down { return(true); } Console.WriteLine($@"Attempting to assign current window to fader {faderNumber}"); if (assigned) { Unassign(); parent.SaveAssignments(); } else { var pid = WindowTools.GetForegroundPID(); var mixerSession = parent.audioDevice.FindMixerSessions(pid); if (mixerSession != null) { Assign(mixerSession); parent.SaveAssignments(); } else { Console.WriteLine($@"MixerSession not found for pid {pid}"); } } return(true); } // Mute match if (assigned && Match(faderNumber, e.MidiEvent, faderDef.muteCode, faderDef.muteOffset, faderDef.muteChannelOverride)) { if (GetValue(e.MidiEvent) != 127) // Only on button-down { return(true); } SetMuteLight(assignment.ToggleMute()); if (assignment.IsDead()) { SetRecordLight(true); } return(true); } // Record match if (assigned && Match(faderNumber, e.MidiEvent, faderDef.recordCode, faderDef.recordOffset, faderDef.recordChannelOverride)) { SetRecordLight(assignment.IsDead()); return(true); } return(false); }
public bool HandleEvent(MidiInMessageEventArgs e) { if (!IsHandling()) { SetHandling(true); //if loaded inactive, search again if (!assigned && identifier != null && !identifier.Equals("")) { assignment = parent.audioDevices.FindMixerSession(identifier); if (assignment != null) { assigned = true; } } // Fader match if (assigned && Match(faderNumber, e.MidiEvent, faderDef.faderCode, faderDef.faderOffset, faderDef.faderChannelOverride)) { var hardwareValue = GetValue(e.MidiEvent); primaryFaderHardwareValue = hardwareValue; return(SetVolume(hardwareValue)); } // SubFader Match if ( faderDef.subFaderPresent && assigned && Match(faderNumber, e.MidiEvent, faderDef.subFaderCode, faderDef.subFaderOffset, faderDef.subFaderChannelOverride)) { this.faderPositionMultiplier = GetValue(e.MidiEvent) / faderDef.faderRange; this.steps = calculateSteps(); return(SetVolume(primaryFaderHardwareValue)); } // Select match if ( faderDef.selectPresent && Match(faderNumber, e.MidiEvent, faderDef.selectCode, faderDef.selectOffset, faderDef.selectChannelOverride) ) { if (GetValue(e.MidiEvent) != 127) // Only on button-down { return(true); } Console.WriteLine($@"Attempting to assign current window to fader {faderNumber}"); if (assigned) { Unassign(); parent.SaveAssignments(); } else { var pid = WindowTools.GetForegroundPID(); var mixerSession = parent.audioDevices.FindMixerSession(pid); if (mixerSession != null) { Assign(mixerSession); parent.SaveAssignments(); } else { Console.WriteLine($@"MixerSession not found for pid {pid}"); } } return(true); } // Mute match if ( faderDef.mutePresent && assigned && Match(faderNumber, e.MidiEvent, faderDef.muteCode, faderDef.muteOffset, faderDef.muteChannelOverride) ) { if (GetValue(e.MidiEvent) != 127) // Only on button-down { return(true); } var muteStatus = assignment.ToggleMute(); SetMuteLight(muteStatus); if (assignment.IsDead()) { SetRecordLight(true); return(true); } List <Fader> fadersToAffect = GetMatchingFaders(); fadersToAffect.ForEach(fader => fader.SetMuteLight(muteStatus)); return(true); } // Record match if ( faderDef.recordPresent && assigned && applicationPath != null && Match(faderNumber, e.MidiEvent, faderDef.recordCode, faderDef.recordOffset, faderDef.recordChannelOverride) ) { if (GetValue(e.MidiEvent) != 127) // Only on button-down { return(true); } if (WindowTools.IsProcessByNameRunning(applicationName)) { SetRecordLight(false); } else { WindowTools.StartApplication(applicationPath); } return(true); } } return(false); }