Example #1
0
 void IEventQueue.QueueEvent(Protocol.Event e)
 {
     lock (eventQueueLock)
     {
         EventQueue.Enqueue(e);
     }
 }
        public void OnBrowserItemChanged(Protocol.Event e)
        {
            int    itemIndex = e.BrowserEvent.OnBrowserItemChangedEvent.ItemIndex;
            string itemName  = e.BrowserEvent.OnBrowserItemChangedEvent.ItemName;

            browserColumn.UpdateItem(itemIndex, itemName);
            browserColumn.SetItemVisibility(itemIndex, itemName.Length > 0 && !itemName.Equals("Results"));

            //Make default selection
            if (State.SelectedItemIndex == -1 && itemName.Equals(Config.DefaultSelection))
            {
                OnItemSelected(itemIndex);
            }

            bool itemIsSelected = State.SelectedItemIndex == itemIndex && itemName.Equals(State.SelectedItemName);

            if (itemIsSelected)
            {
                browserColumn.SelectItem(itemIndex);
            }
            else
            {
                browserColumn.DeselectItem(itemIndex);
            }
        }
Example #3
0
        public void RouteEvent(Protocol.Event e)
        {
            string receiverID = "";

            switch (e.EventCase)
            {
            case Protocol.Event.EventOneofCase.ModuleEvent:
                receiverID = e.ModuleEvent.HandlerId;
                break;

            case Protocol.Event.EventOneofCase.BrowserEvent:
                receiverID = "browser" + e.BrowserEvent.Path;
                break;

            default:
                Debug.LogError("Event not recognized");
                break;
            }

            if (getHandlerDictionary().ContainsKey(receiverID))
            {
                RemoteEventHandler receiver = getHandlerDictionary()[receiverID];
                receiver.HandleEvent(e);
            }
        }
Example #4
0
        public void EmitEvent(Protocol.Event outgoingEvent)
        {
            try
            {
                //Debug.Log("Sending event " + outgoingEvent.MethodName);
                NetworkStream networkStream = State.Client.GetStream();

                //Clear the output stream
                State.OutStream.SetLength(0);

                //Bitwig requires a 32bit integer header specifying the length of the data to follow
                byte[] header = BitConverter.GetBytes(outgoingEvent.CalculateSize() + 1); //Add 1 to the calculated size to account for the delimiter

                //The header must be in big endian format
                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(header, 0, header.Length);
                }

                //Write the data and the header to the stream
                State.OutStream.Write(header, 0, header.Length);
                outgoingEvent.WriteDelimitedTo(State.OutStream);

                //Get the data from the memory stream and write it to the network stream
                byte[] data = State.OutStream.ToArray();
                networkStream.BeginWrite(data, 0, data.Length, new AsyncCallback(WriteCallback), data);
            }
            catch (IOException e)
            {
                Debug.LogError("Can't emit event. Not connected.");
            }
        }
Example #5
0
        /// <summary>
        /// This method parses an event from a stream and queues it
        /// </summary>
        /// <param name="s"> This stream should contain one complete event with no delimiter </param>
        private void QueueNextMessageInStream(MemoryStream s)
        {
            s.Seek(messageStartLoc, SeekOrigin.Begin);

            Protocol.Event incomingEvent = Protocol.Event.Parser.ParseDelimitedFrom(s);
            EventQueue.QueueEvent(incomingEvent);

            State.LengthStream.SetLength(0);
        }
Example #6
0
        public void HandleEvent(Protocol.Event e)
        {
            Type       thisType  = this.GetType();
            MethodInfo theMethod = thisType.GetMethod(e.MethodName);

            if (theMethod != null)
            {
                theMethod.Invoke(this, new object[] { e });
            }
        }
        public void OnBrowserColumnChanged(Protocol.Event e)
        {
            int totalResults   = e.BrowserEvent.OnBrowserColumnChangedEvent.TotalResults;
            int resultsPerPage = e.BrowserEvent.OnBrowserColumnChangedEvent.ResultsPerPage;

            browserColumn.ExpandToSize(resultsPerPage);
            State.ColumnSize = Math.Max(resultsPerPage, State.ColumnSize);

            if (DeviceTypeChanged != null)
            {
                var args = new DeviceTypeChangedEventArgs(e.BrowserEvent.OnBrowserColumnChangedEvent.DeviceType);
                DeviceTypeChanged(this, args);
            }
        }
        public void OnArrowVisibilityChanged(Protocol.Event e)
        {
            Protocol.Browser.OnArrowVisibilityChanged visChanged = e.BrowserEvent.OnArrowVisibilityChangedEvent;

            if (visChanged.Arrow == Arrow.Up)
            {
                State.UpArrowVisible = visChanged.Visible;
            }
            else
            {
                State.DownArrowVisible = visChanged.Visible;
            }

            browserColumn.SetArrowVisibility(visChanged.Arrow, visChanged.Visible);
        }
Example #9
0
        public void send(Protocol.Event outgoingEvent)
        {
            try
            {
                outStream.SetLength(0);
                outgoingEvent.WriteDelimitedTo(outStream);

                byte[] data = outStream.ToArray();

                sender.SendTo(data, send_end_point);
            }
            catch (Exception sendException)
            {
                Debug.Log("Dgram send error: " + sendException.Message);
            }
        }
Example #10
0
        public void ChangeResultsPage(int pageChange)
        {
            Protocol.Browser.ChangeResultsPage changeResultsEvent = new Protocol.Browser.ChangeResultsPage
            {
                PageChange = pageChange
            };

            Protocol.BrowserEvent browserEvent = new Protocol.BrowserEvent
            {
                Path = "",
                ChangeResultsPageEvent = changeResultsEvent
            };

            Protocol.Event remoteEvent = new Protocol.Event
            {
                BrowserEvent = browserEvent,
                MethodName   = "ChangeResultsPage"
            };

            Emitter.EmitEvent(remoteEvent);
        }
Example #11
0
        public void CloseBrowser()
        {
            Protocol.Browser.CloseBrowser closeEvent = new Protocol.Browser.CloseBrowser
            {
                Commit = true
            };

            Protocol.BrowserEvent browserEvent = new Protocol.BrowserEvent
            {
                Path = "",
                CloseBrowserEvent = closeEvent
            };

            Protocol.Event remoteEvent = new Protocol.Event
            {
                BrowserEvent = browserEvent,
                MethodName   = "CloseBrowser"
            };

            Emitter.EmitEvent(remoteEvent);
        }
Example #12
0
        public void LoadDeviceAtIndex(int selectionIndex)
        {
            Protocol.Browser.LoadDeviceAtIndex loadEvent = new Protocol.Browser.LoadDeviceAtIndex
            {
                Index = selectionIndex
            };

            Protocol.BrowserEvent browserEvent = new Protocol.BrowserEvent
            {
                Path = "",
                LoadDeviceAtIndexEvent = loadEvent
            };

            Protocol.Event remoteEvent = new Protocol.Event
            {
                BrowserEvent = browserEvent,
                MethodName   = "LoadDeviceAtIndex"
            };

            Emitter.EmitEvent(remoteEvent);
        }
Example #13
0
        public void CommitSelection(bool commit)
        {
            Protocol.Browser.CommitSelection commitSelection = new Protocol.Browser.CommitSelection
            {
                Commit = commit
            };

            Protocol.BrowserEvent browserEvent = new Protocol.BrowserEvent
            {
                Path = "",
                CommitSelectionEvent = commitSelection
            };

            Protocol.Event remoteEvent = new Protocol.Event
            {
                BrowserEvent = browserEvent,
                MethodName   = "CommitSelection"
            };

            Emitter.EmitEvent(remoteEvent);
        }
Example #14
0
        public void SelectResult(int selectionIndex)
        {
            Protocol.Browser.SelectResult selectResult = new Protocol.Browser.SelectResult
            {
                Index = selectionIndex
            };

            Protocol.BrowserEvent browserEvent = new Protocol.BrowserEvent
            {
                Path = "",
                SelectResultEvent = selectResult
            };

            Protocol.Event remoteEvent = new Protocol.Event
            {
                BrowserEvent = browserEvent,
                MethodName   = "SelectResult"
            };

            Emitter.EmitEvent(remoteEvent);
        }
Example #15
0
        /// <summary>
        /// Creates a new sound module (corresponding to a new track) on the DAW
        /// </summary>
        /// <param name="client"></param>
        /// <param name="senderID"> The id to give the sound module</param>
        public void CreateSoundModule(string senderID)
        {
            Protocol.Module.CreateSoundModule createEvent = new Protocol.Module.CreateSoundModule
            {
                SenderId = senderID
            };

            Protocol.ModuleEvent moduleEvent = new Protocol.ModuleEvent
            {
                HandlerId = "app",
                CreateSoundModuleEvent = createEvent
            };

            Protocol.Event remoteEvent = new Protocol.Event
            {
                ModuleEvent = moduleEvent,
                MethodName  = "CreateSoundModule"
            };

            Emitter.EmitEvent(remoteEvent);
        }
Example #16
0
        public void ChangeFilterPage(string columnName, int pageChange)
        {
            Protocol.Browser.ChangeFilterPage changeFilterEvent = new Protocol.Browser.ChangeFilterPage
            {
                ColumnName = columnName,
                PageChange = pageChange
            };

            Protocol.BrowserEvent browserEvent = new Protocol.BrowserEvent
            {
                Path = "/filter",
                ChangeFilterPageEvent = changeFilterEvent
            };

            Protocol.Event remoteEvent = new Protocol.Event
            {
                BrowserEvent = browserEvent,
                MethodName   = "ChangeFilterPage"
            };

            Emitter.EmitEvent(remoteEvent);
        }
Example #17
0
        public void SelectFilterItem(string columnName, int selectionIndex)
        {
            Protocol.Browser.SelectFilterItem selectFilterEvent = new Protocol.Browser.SelectFilterItem
            {
                ColumnName = columnName,
                ItemIndex  = selectionIndex
            };

            Protocol.BrowserEvent browserEvent = new Protocol.BrowserEvent
            {
                Path = "/filter",
                SelectFilterItemEvent = selectFilterEvent
            };

            Protocol.Event remoteEvent = new Protocol.Event
            {
                BrowserEvent = browserEvent,
                MethodName   = "SelectFilterItem"
            };

            Emitter.EmitEvent(remoteEvent);
        }
Example #18
0
        // Update is called once per frame
        void Update()
        {
            int eventCount = 0;

            lock (eventQueueLock)
            {
                if (EventQueue != null)
                {
                    eventCount = EventQueue.Count;
                }
            }

            //Set the time to stop processing incoming events, otherwise the frame may hang
            float timeout = Time.realtimeSinceStartup + maxUpdateTime;

            while (eventCount > 0)
            {
                if (Time.realtimeSinceStartup > timeout)
                {
                    break;
                }

                //Try to get an event from the queue
                Protocol.Event currentEvent = null;
                lock (eventQueueLock)
                {
                    currentEvent = EventQueue.Dequeue();
                }

                //Send the event on to its target object
                if (currentEvent != null)
                {
                    RemoteEventRouter.Instance.RouteEvent(currentEvent);
                }

                eventCount--;
            }
        }
Example #19
0
        /// <summary>
        /// Opens a browser on a module
        /// </summary>
        /// <param name="client"></param>
        /// <param name="moduleID">The module to browse on</param>
        public void OpenBrowser(string moduleID, string deviceType, string contentType, int deviceIndex, bool replaceDevice)
        {
            Protocol.Module.OpenBrowser openEvent = new Protocol.Module.OpenBrowser
            {
                DeviceType    = deviceType,
                ContentType   = contentType,
                DeviceIndex   = deviceIndex,
                ReplaceDevice = replaceDevice
            };

            Protocol.ModuleEvent moduleEvent = new Protocol.ModuleEvent
            {
                HandlerId        = moduleID,
                OpenBrowserEvent = openEvent
            };

            Protocol.Event remoteEvent = new Protocol.Event
            {
                ModuleEvent = moduleEvent,
                MethodName  = "OpenBrowser"
            };

            Emitter.EmitEvent(remoteEvent);
        }
Example #20
0
 /// <summary>
 /// Event triggered after the DAW has successfully created a new sound module
 /// </summary>
 ///
 public void OnSoundModuleCreated(Protocol.Event e)
 {
     Debug.Log("Track created with id " + GetID());
     RequestBrowser("Instrument", "Devices", 0, false, false);
 }