예제 #1
0
 private void Midi_OnMidiOutput(CMidiObserver sender, SMidiAction data)
 {
     if (Device != null)
     {
         Device.Send(data);
     }
 }
예제 #2
0
 private void _sendMidiCmd(SMidiAction action)
 {
     if (OnMidiOutput != null)
     {
         OnMidiOutput(this, action);
     }
 }
예제 #3
0
 private void MidiObserver_OnMidiOutput(CMidiObserver sender, SMidiAction data)
 {
     if (Device != null)
     {
         //Console.WriteLine(data.Cmd.ToString("x2") + ", " + data.Data1.ToString("x2") + ", " + data.Data2.ToString("x2"));
         Device.Send(data);
     }
 }
예제 #4
0
 private void Device_OnData(IOBSDevice sender, SMidiAction data)
 {
     /* Console.Write(data.Cmd.ToString("X2")+" ");
      * Console.Write(data.Channel.ToString("X2") + " ");
      * Console.Write(data.Data1.ToString("X2") + " ");
      * Console.WriteLine(data.Data2.ToString("X2") + " ");
      */
     MidiObserver.ParseInputData(data);
 }
예제 #5
0
        public void SendMidiCommand(SMidiAction action)
        {
            string targetId = action.Data1.ToString("X2") + "_" + action.Channel.ToString("X2");

            if (midiQueue.ContainsKey(targetId))
            {
                midiQueue[targetId] = action;
            }
            else
            {
                midiQueue.Add(targetId, action);
            }

            FlushQueue();
        }
예제 #6
0
        public bool checkLastOutputStatus(SMidiAction o)
        {
            string targetId = o.Data1.ToString("X2"); // + "_" + o.Channel.ToString("X2")

            if (midiOutputStatus.ContainsKey(targetId))
            {
                if (midiOutputStatus[targetId].Cmd == o.Cmd &&
                    midiOutputStatus[targetId].Data2 == o.Data2 &&
                    midiOutputStatus[targetId].Channel == o.Channel
                    )
                {
                    return(false);
                }

                midiOutputStatus[targetId] = o;
            }
            else
            {
                midiOutputStatus.Add(targetId, o);
            }
            return(true);
        }
예제 #7
0
        public void ParseInputData(SMidiAction action)
        {
            for (int m = 0; m < midiActions.Count(); m++)
            {
                if ((int)obs.Mode == midiActions[m].ObsMode || midiActions[m].ObsMode == 0)
                {
                    if (midiActions[m].Type == EMidiOBSItemType.Modifier ||
                        (midiActions[m].Type != EMidiOBSItemType.Modifier && midiActions[m].Modifier == active_modifier) ||
                        (midiActions[m].Type != EMidiOBSItemType.Modifier && midiActions[m].Modifier == -1)
                        )
                    {
                        for (int i = 0; i < midiActions[m].InActions.Count(); i++)
                        {
                            if (action.Cmd == midiActions[m].InActions[i].Action.Cmd &&
                                action.Data1 == midiActions[m].InActions[i].Action.Data1
                                )
                            {
                                //Modifier button pressed
                                if (midiActions[m].Type == EMidiOBSItemType.Modifier)
                                {
                                    if (action.Data2 == midiActions[m].InActions[i].Action.Data2)
                                    {
                                        if (midiActions[m].InActions[i].Type == EMidiOBSInputType.On)
                                        {
                                            active_modifier = midiActions[m].Modifier;
                                        }
                                        else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Off)
                                        {
                                            active_modifier = 0;
                                        }
                                        else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Toggle)
                                        {
                                            if (active_modifier != midiActions[m].Modifier)
                                            {
                                                active_modifier = midiActions[m].Modifier;
                                            }
                                            else
                                            {
                                                active_modifier = 0;
                                            }
                                        }
                                        RenderSurface();
                                    }
                                }

                                //Input modifier match or any modifier
                                else if (midiActions[m].Modifier == active_modifier || midiActions[m].Modifier == -1)
                                {
                                    //Data2 match or any Data2 value
                                    if (action.Data2 == midiActions[m].InActions[i].Action.Data2 || midiActions[m].InActions[i].Action.Data2 == -1)
                                    {
                                        //
                                        // Scene
                                        //
                                        if (midiActions[m].Type == EMidiOBSItemType.Scene || midiActions[m].Type == EMidiOBSItemType.Pscene)
                                        {
                                            if (midiActions[m].InActions[i].Type == EMidiOBSInputType.On)
                                            {
                                                if (midiActions[m].Index < obs.Scenes.Count())
                                                {
                                                    if (midiActions[m].Type == EMidiOBSItemType.Pscene)
                                                    {
                                                        obs.SwitchPreviewScene(midiActions[m].Index);
                                                    }
                                                    else
                                                    {
                                                        obs.SwitchScene(midiActions[m].Index);
                                                    }
                                                }
                                            }
                                        }

                                        //
                                        // Scene Item
                                        //

                                        else if (midiActions[m].Type == EMidiOBSItemType.SceneItem || midiActions[m].Type == EMidiOBSItemType.PsceneItem)
                                        {
                                            int sscene_id = 0;
                                            if (midiActions[m].Type == EMidiOBSItemType.PsceneItem && (int)obs.Mode == 2)
                                            {
                                                sscene_id = obs.ActivePreviewScene.Index;
                                            }
                                            else
                                            {
                                                sscene_id = obs.ActiveScene.Index;
                                            }

                                            if (sscene_id < obs.Scenes.Count())
                                            {
                                                if (midiActions[m].InActions[i].Type == EMidiOBSInputType.On)
                                                {
                                                    obs.SetSceneItemVisibility(sscene_id, midiActions[m].Index, true);
                                                }
                                                else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Off)
                                                {
                                                    obs.SetSceneItemVisibility(sscene_id, midiActions[m].Index, false);
                                                }
                                                else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Toggle)
                                                {
                                                    obs.ToggleSceneItemVisibility(sscene_id, midiActions[m].Index);
                                                }
                                            }
                                        }

                                        //
                                        // Audio Item (Mute buttons)
                                        //
                                        else if (midiActions[m].Type == EMidiOBSItemType.AudioItem)
                                        {
                                            if (midiActions[m].InActions[i].Type == EMidiOBSInputType.On)
                                            {
                                                obs.SetSourceAudioMute(midiActions[m].Index, true);
                                            }
                                            else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Off)
                                            {
                                                obs.SetSourceAudioMute(midiActions[m].Index, false);
                                            }
                                            else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Toggle)
                                            {
                                                obs.ToggleSourceAudioMute(midiActions[m].Index);
                                            }
                                        }

                                        //
                                        // Reload all data from OBS
                                        //
                                        else if (midiActions[m].Type == EMidiOBSItemType.ReloadObsData)
                                        {
                                            if (midiActions[m].InActions[i].Type == EMidiOBSInputType.On || midiActions[m].InActions[i].Type == EMidiOBSInputType.Toggle)
                                            {
                                                obs.Reload();
                                            }
                                        }

                                        //
                                        // Reload all data from OBS
                                        //
                                        else if (midiActions[m].Type == EMidiOBSItemType.ReloadScheme)
                                        {
                                            if (midiActions[m].InActions[i].Type == EMidiOBSInputType.On || midiActions[m].InActions[i].Type == EMidiOBSInputType.Toggle)
                                            {
                                                ReloadScheme();
                                            }
                                        }

                                        //
                                        // Start/Stop streaming
                                        //
                                        else if (midiActions[m].Type == EMidiOBSItemType.Stream)
                                        {
                                            if (midiActions[m].InActions[i].Type == EMidiOBSInputType.On)
                                            {
                                                obs.StartStreaming();
                                            }
                                            else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Off)
                                            {
                                                obs.StopStreaming();
                                            }
                                            else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Toggle)
                                            {
                                                obs.ToggleStreaming();
                                            }
                                        }

                                        //
                                        // Start/Stop recording
                                        //
                                        else if (midiActions[m].Type == EMidiOBSItemType.Record)
                                        {
                                            if (midiActions[m].InActions[i].Type == EMidiOBSInputType.On)
                                            {
                                                obs.StartRecording();
                                            }
                                            else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Off)
                                            {
                                                obs.StopRecording();
                                            }
                                            else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Toggle)
                                            {
                                                obs.ToggleRecording();
                                            }
                                        }

                                        //
                                        // Start/Stop replay buffer
                                        //
                                        else if (midiActions[m].Type == EMidiOBSItemType.ReplayBuffer)
                                        {
                                            if (midiActions[m].InActions[i].Type == EMidiOBSInputType.On)
                                            {
                                                obs.StartReplayBuffer();
                                            }
                                            else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Off)
                                            {
                                                obs.StopReplayBuffer();
                                            }
                                            else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Toggle)
                                            {
                                                obs.ToggleReplayBuffer();
                                            }
                                        }

                                        //
                                        // Save replay buffer
                                        //
                                        else if (midiActions[m].Type == EMidiOBSItemType.ReplayBufferSave)
                                        {
                                            if (midiActions[m].InActions[i].Type == EMidiOBSInputType.On)
                                            {
                                                obs.SaveReplayBuffer();
                                            }
                                            else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Toggle)
                                            {
                                                obs.SaveReplayBuffer();
                                            }
                                        }

                                        //
                                        // Switch mode
                                        //
                                        else if (midiActions[m].Type == EMidiOBSItemType.Mode)
                                        {
                                            if (midiActions[m].InActions[i].Type == EMidiOBSInputType.On)
                                            {
                                                if ((int)obs.Mode != 2)
                                                {
                                                    obs.SetStudioMode(true);
                                                }
                                            }
                                            else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Off)
                                            {
                                                if ((int)obs.Mode == 2)
                                                {
                                                    obs.SetStudioMode(false);
                                                }
                                            }
                                            else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Toggle)
                                            {
                                                //obs.SetStudioMode((int)obs.Mode != 2 ? true : false);
                                                obs.ToggleStudioMode();
                                            }
                                        }

                                        //
                                        // Transition item
                                        //
                                        else if (midiActions[m].Type == EMidiOBSItemType.Transition)
                                        {
                                            if (midiActions[m].Index < obs.Transitions.Count())
                                            {
                                                if (midiActions[m].InActions[i].Type == EMidiOBSInputType.On || midiActions[m].InActions[i].Type == EMidiOBSInputType.Toggle)
                                                {
                                                    obs.SetTransition(midiActions[m].Index);
                                                }
                                            }
                                        }

                                        //Data2 match not required
                                    }
                                    else
                                    {
                                        //
                                        // Audio Volume (for sliders)
                                        //
                                        if (midiActions[m].Type == EMidiOBSItemType.AudioVolume)
                                        {
                                            if (midiActions[m].InActions[i].Type == EMidiOBSInputType.On)
                                            {
                                                obs.SetSourceAudioVolume(midiActions[m].Index, 1);
                                            }
                                            else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Off)
                                            {
                                                obs.SetSourceAudioVolume(midiActions[m].Index, 0);
                                            }
                                            else if (midiActions[m].InActions[i].Type == EMidiOBSInputType.Value)
                                            {
                                                float mappedValue = Map(action.Data2, 0, 127, 0, 1);
                                                obs.SetSourceAudioVolume(midiActions[m].Index, mappedValue);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                } //obsmode
            }     //for
        }
예제 #8
0
 private void Device_OnData(IOBSDevice sender, SMidiAction data)
 {
     Midi.ParseInputData(data);
 }