コード例 #1
0
ファイル: Fader.cs プロジェクト: nathanojb/NK2Tray
        /// <summary>
        /// This method sets the volume of the assigned ( if any ) application.
        /// It utilises the "hardwarePosition" passed as a parameter but in sub calls it will
        /// augment that value with the value of "faderPositionMultiplier" which is set elsewhere
        /// </summary>
        /// <param name="hardwarePosition">Position of the primary fader as reported by the MidiDevice</param>
        /// <returns></returns>
        private bool SetVolume(int hardwarePosition)
        {
            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         = hardwarePosition;
                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.faderRange / 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 = getVolumeFromHardwarePositionUsingMultiplier(hardwarePosition);
                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);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: vabene1111/NK2Tray
        private void OnPopup(object sender, EventArgs e)
        {
            ContextMenu trayMenu = (ContextMenu)sender;

            trayMenu.MenuItems.Clear();

            var mixerSessions      = audioDevice.GetMixerSessions();
            var masterMixerSession = new MixerSession(audioDevice, "Master", SessionType.Master, audioDevice.GetDeviceVolumeObject());

            foreach (var fader in midiDevice.faders)
            {
                MenuItem faderMenu = new MenuItem($@"Fader {fader.faderNumber + 1} - {(fader.assigned ? fader.assignment.label : "")}");
                trayMenu.MenuItems.Add(faderMenu);

                // Add master mixerSession to menu
                MenuItem masterItem = new MenuItem(masterMixerSession.label, AssignFader);
                masterItem.Tag = new object[] { fader, masterMixerSession };
                faderMenu.MenuItems.Add(masterItem);

                // Add application mixer sessions to each fader
                foreach (var mixerSession in mixerSessions)
                {
                    MenuItem si = new MenuItem(mixerSession.label, AssignFader);
                    si.Tag = new object[] { fader, mixerSession };
                    faderMenu.MenuItems.Add(si);
                }

                // Add unassign option
                MenuItem unassignItem = new MenuItem("UNASSIGN", UnassignFader);
                unassignItem.Tag = new object[] { fader };
                faderMenu.MenuItems.Add(unassignItem);
            }

            trayMenu.MenuItems.Add("Exit", OnExit);
        }
コード例 #3
0
ファイル: Fader.cs プロジェクト: vabene1111/NK2Tray
 public void Unassign()
 {
     assigned   = false;
     assignment = null;
     SetSelectLight(false);
     identifier = "";
     if (faderDef.delta)
     {
         parent.SetVolumeIndicator(faderNumber, -1);
     }
 }
コード例 #4
0
ファイル: Fader.cs プロジェクト: vabene1111/NK2Tray
 public void Assign(MixerSession mixerSession)
 {
     assigned   = true;
     assignment = mixerSession;
     identifier = mixerSession.sessionIdentifier;
     SetSelectLight(true);
     SetRecordLight(false);
     if (faderDef.delta)
     {
         parent.SetVolumeIndicator(faderNumber, mixerSession.GetVolume());
     }
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: Chaosgabe/NK2Tray
        private void OnPopup(object sender, EventArgs e)
        {
            ContextMenu trayMenu = (ContextMenu)sender;

            trayMenu.MenuItems.Clear();

            var mixerSessions      = audioDevice.GetMixerSessions();
            var masterMixerSession = new MixerSession(audioDevice, "Master", SessionType.Master, audioDevice.GetDeviceVolumeObject());

            var focusMixerSession = new MixerSession(audioDevice, "Focus", SessionType.Focus, audioDevice.GetDeviceVolumeObject());

            // Dont create context menu if no midi device is connected
            if (!midiDevice.Found)
            {
                if (!SetupDevice()) // This setup call can be removed once proper lifecycle management is implemented, for now this also adds a nice way to reconnect the controller
                {
                    MessageBox.Show("No midi device detected. Are you sure your device is plugged in correctly ?");
                    return;
                }
            }

            foreach (var fader in midiDevice.faders)
            {
                MenuItem faderMenu = new MenuItem($@"Fader {fader.faderNumber + 1} - {(fader.assigned ? fader.assignment.label : "")}");
                trayMenu.MenuItems.Add(faderMenu);

                // Add master mixerSession to menu
                MenuItem masterItem = new MenuItem(masterMixerSession.label, AssignFader);
                masterItem.Tag = new object[] { fader, masterMixerSession };
                faderMenu.MenuItems.Add(masterItem);

                // Add focus mixerSession to menu
                MenuItem focusItem = new MenuItem(focusMixerSession.label, AssignFader);
                focusItem.Tag = new object[] { fader, focusMixerSession };
                faderMenu.MenuItems.Add(focusItem);

                // Add application mixer sessions to each fader
                foreach (var mixerSession in mixerSessions)
                {
                    MenuItem si = new MenuItem(mixerSession.label, AssignFader);
                    si.Tag = new object[] { fader, mixerSession };
                    faderMenu.MenuItems.Add(si);
                }

                // Add unassign option
                MenuItem unassignItem = new MenuItem("UNASSIGN", UnassignFader);
                unassignItem.Tag = new object[] { fader };
                faderMenu.MenuItems.Add(unassignItem);
            }

            trayMenu.MenuItems.Add("Exit", OnExit);
        }
コード例 #6
0
        public bool HasCrossoverProcesses(MixerSession other)
        {
            if (other == null)
            {
                return(false);
            }

            return(audioSessions.Any(session =>
                                     other.audioSessions.Any(otherSession =>
                                                             session.GetProcessID == otherSession.GetProcessID
                                                             )
                                     ));
        }
コード例 #7
0
 public void Assign(MixerSession mixerSession)
 {
     assigned   = true;
     assignment = mixerSession;
     identifier = mixerSession.sessionIdentifier;
     convertToApplicationPath(identifier);
     applicationName = mixerSession.label;
     SetSelectLight(true);
     SetRecordLight(false);
     if (faderDef.delta)
     {
         parent.SetVolumeIndicator(faderNumber, mixerSession.GetVolume());
     }
 }
コード例 #8
0
ファイル: AudioDevice.cs プロジェクト: maicomstoppa/NK2Tray
        private List <MixerSession> GetMixerSessions()
        {
            var mixerSessions   = new List <MixerSession>();
            var sessionsByIdent = new Dictionary <String, List <AudioSessionControl> >();

            UpdateDevices();
            for (int j = 0; j < devices.Count; j++)
            {
                var sessions = devices[j].AudioSessionManager.Sessions;

                for (int i = 0; i < sessions.Count; i++)
                {
                    var session = sessions[i];
                    if (session.State != AudioSessionState.AudioSessionStateExpired)
                    {
                        String searchIdentifier = session.GetSessionIdentifier.Substring(session.GetSessionIdentifier.IndexOf("|") + 1, session.GetSessionIdentifier.Length - session.GetSessionIdentifier.IndexOf("|") - 1);
                        if (!sessionsByIdent.ContainsKey(searchIdentifier))
                        {
                            sessionsByIdent[searchIdentifier] = new List <AudioSessionControl>();
                        }

                        sessionsByIdent[searchIdentifier].Add(session);
                    }
                }
            }

            foreach (var ident in sessionsByIdent.Keys.ToList())
            {
                var identSessions = sessionsByIdent[ident]; //.OrderBy(i => (int)Process.GetProcessById((int)i.GetProcessID).MainWindowHandle).ToList();

                bool dup = identSessions.Count > 1;

                SessionType sessionType = SessionType.Application;

                var    process = FindLivingProcess(identSessions);
                string label   = (process != null) ? process.ProcessName : ident;

                if (HasSystemSoundsSession(identSessions))
                {
                    label = "System Sounds";
                }

                var mixerSession = new MixerSession(this, label, ident, identSessions, sessionType);
                mixerSessions.Add(mixerSession);
            }

            return(mixerSessions);
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: jacktm22/NK2Tray
        private void OnPopup(object sender, EventArgs e)
        {
            ContextMenu trayMenu = (ContextMenu)sender;

            trayMenu.MenuItems.Clear();

            var mixerSessions = audioDevices.GetCachedMixerSessions();

            var masterMixerSessionList = new List <MixerSession>();

            foreach (MMDevice mmDevice in audioDevices.outputDevices)
            {
                masterMixerSessionList.Add(new MixerSession(mmDevice.ID, audioDevices, "Master", SessionType.Master));
            }

            /*
             * // Commented out Iput device code because it breaks the session lists when input and ouput is controlled at the same time
             * var micMixerSessionList = new List<MixerSession>();
             * foreach (MMDevice mmDevice in audioDevices.inputDevices)
             * {
             *  micMixerSessionList.Add(new MixerSession(mmDevice.ID, audioDevices, "Microphone", SessionType.Master));
             * }
             */

            MixerSession focusMixerSession;

            focusMixerSession = new MixerSession("", audioDevices, "Focus", SessionType.Focus);

            // Dont create context menu if no midi device is connected
            if (!midiDevice.Found)
            {
                if (!SetupDevice()) // This setup call can be removed once proper lifecycle management is implemented, for now this also adds a nice way to reconnect the controller
                {
                    MessageBox.Show("No midi device detected. Are you sure your device is plugged in correctly?");
                    return;
                }
            }

            foreach (var fader in midiDevice.faders)
            {
                MenuItem faderMenu = new MenuItem($@"Fader {fader.faderNumber + 1} - " + getProgramLabel(fader));
                trayMenu.MenuItems.Add(faderMenu);

                // Add master mixerSession to menu
                foreach (MixerSession mixerSession in masterMixerSessionList)
                {
                    MenuItem masterItem = new MenuItem(mixerSession.label, AssignFader);
                    masterItem.Tag = new object[] { fader, mixerSession };
                    faderMenu.MenuItems.Add(masterItem);
                }

                /*
                 * // Commented out Iput device code because it breaks the session lists when input and ouput is controlled at the same time
                 * faderMenu.MenuItems.Add("-");
                 *
                 * foreach (MixerSession mixerSession in micMixerSessionList)
                 * {
                 *  MenuItem micItem = new MenuItem(mixerSession.label, AssignFader);
                 *  micItem.Tag = new object[] { fader, mixerSession };
                 *  faderMenu.MenuItems.Add(micItem);
                 * }
                 */

                faderMenu.MenuItems.Add("-");

                // Add focus mixerSession to menu
                MenuItem focusItem = new MenuItem(focusMixerSession.label, AssignFader);
                focusItem.Tag = new object[] { fader, focusMixerSession };
                faderMenu.MenuItems.Add(focusItem);

                faderMenu.MenuItems.Add("-");

                // Add application mixer sessions to each fader
                foreach (var mixerSession in mixerSessions)
                {
                    MenuItem si = new MenuItem(mixerSession.label, AssignFader);
                    si.Tag = new object[] { fader, mixerSession };
                    faderMenu.MenuItems.Add(si);
                }

                faderMenu.MenuItems.Add("-");

                // Add unassign option
                MenuItem unassignItem = new MenuItem("Unassign", UnassignFader);
                unassignItem.Tag = new object[] { fader };
                faderMenu.MenuItems.Add(unassignItem);
            }

            trayMenu.MenuItems.Add("Exit", OnExit);
        }
コード例 #10
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);
        }
コード例 #11
0
ファイル: AudioDevice.cs プロジェクト: pilo1337/NK2Tray
        private List <MixerSession> GetMixerSessions()
        {
            var mixerSessions   = new List <MixerSession>();
            var sessionsByIdent = new Dictionary <String, List <AudioSessionControl> >();

            UpdateDevices();
            for (int j = 0; j < outputDevices.Count; j++)
            {
                var sessions = outputDevices[j].AudioSessionManager.Sessions;

                for (int i = 0; i < sessions.Count; i++)
                {
                    var session = sessions[i];
                    if (session.State != AudioSessionState.AudioSessionStateExpired)
                    {
                        String searchIdentifier = session.GetSessionIdentifier.Substring(session.GetSessionIdentifier.IndexOf("|") + 1, session.GetSessionIdentifier.Length - session.GetSessionIdentifier.IndexOf("|") - 1);
                        if (!sessionsByIdent.ContainsKey(searchIdentifier))
                        {
                            sessionsByIdent[searchIdentifier] = new List <AudioSessionControl>();
                        }

                        sessionsByIdent[searchIdentifier].Add(session);
                    }
                }
            }

            /*
             * // Commented out Iput device code because it breaks the session lists when input and ouput is controlled at the same time
             * for (int j = 0; j < inputDevices.Count; j++)
             * {
             *  var sessions = inputDevices[j].AudioSessionManager.Sessions;
             *  for (int i = 0; i < sessions.Count; i++)
             *  {
             *      var session = sessions[i];
             *      if (session.State != AudioSessionState.AudioSessionStateExpired)
             *      {
             *          String searchIdentifier = session.GetSessionIdentifier.Substring(session.GetSessionIdentifier.IndexOf("|") + 1, session.GetSessionIdentifier.Length - session.GetSessionIdentifier.IndexOf("|") - 1);
             *          if (!sessionsByIdent.ContainsKey(searchIdentifier))
             *              sessionsByIdent[searchIdentifier] = new List<AudioSessionControl>();
             *
             *          sessionsByIdent[searchIdentifier].Add(session);
             *      }
             *  }
             * }
             */

            foreach (var ident in sessionsByIdent.Keys.ToList())
            {
                var identSessions = sessionsByIdent[ident]; //.OrderBy(i => (int)Process.GetProcessById((int)i.GetProcessID).MainWindowHandle).ToList();

                bool dup = identSessions.Count > 1;

                var    process = FindLivingProcess(identSessions);
                string label   = (process != null) ? process.ProcessName : ident;

                if (HasSystemSoundsSession(identSessions))
                {
                    label = "System Sounds";
                }

                var mixerSession = new MixerSession(this, label, ident, identSessions, SessionType.Application);
                mixerSessions.Add(mixerSession);
            }

            return(mixerSessions);
        }
コード例 #12
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;
                    }

                    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);
        }
コード例 #13
0
        public List <Fader> GetMatchingFaders()
        {
            MixerSession focusMixerSession = null;

            bool haveFocusSlider = parent.faders.Any(fader => (
                                                         fader.assignment != null &&
                                                         fader.assignment.sessionType == SessionType.Focus
                                                         ));

            if (haveFocusSlider)
            {
                int pid = WindowTools.GetForegroundPID();
                focusMixerSession = assignment.devices.FindMixerSession(pid);
            }

            if (assignment == null)
            {
                return(parent.faders.FindAll(fader => fader.assignment == null));
            }

            if (assignment.sessionType == SessionType.Master)
            {
                return(parent.faders.FindAll(fader =>
                {
                    if (fader == this)
                    {
                        return true;
                    }
                    if (fader.assignment == null)
                    {
                        return false;
                    }
                    if (fader.assignment.sessionType != SessionType.Master)
                    {
                        return false;
                    }

                    return fader.assignment.parentDeviceIdentifier == assignment.parentDeviceIdentifier;
                }));
            }

            if (assignment.sessionType == SessionType.Focus)
            {
                return(parent.faders.FindAll(fader =>
                {
                    if (fader == this)
                    {
                        return true;
                    }
                    if (fader.assignment == null)
                    {
                        return false;
                    }
                    if (fader.assignment.sessionType == SessionType.Focus)
                    {
                        return true;
                    }

                    return fader.assignment.HasCrossoverProcesses(focusMixerSession);
                }));
            }

            if (assignment.sessionType == SessionType.Application)
            {
                return(parent.faders.FindAll(fader =>
                {
                    if (fader == this)
                    {
                        return true;
                    }
                    if (fader.assignment == null)
                    {
                        return false;
                    }

                    if (fader.assignment.sessionType == SessionType.Application)
                    {
                        return fader.assignment.HasCrossoverProcesses(assignment);
                    }

                    if (fader.assignment.sessionType == SessionType.Focus)
                    {
                        return assignment.HasCrossoverProcesses(focusMixerSession);
                    }

                    return false;
                }));
            }

            if (assignment.sessionType == SessionType.SystemSounds)
            {
                return(parent.faders.FindAll(fader => (
                                                 fader.assignment != null &&
                                                 fader.assignment.sessionType == SessionType.SystemSounds
                                                 )));
            }

            return(new List <Fader>());
        }
コード例 #14
0
ファイル: Fader.cs プロジェクト: nathanojb/NK2Tray
        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);
        }