Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }