Exemple #1
0
        /// <summary>
        /// Sends MIDI messages using the current mapping settings
        /// from this OSC message.
        /// </summary>
        public void OscToMidi(OscDataMessage osc)
        {
            // create midi packet using current mapping settings
            OscToMidiMap mapping;
            var          midi = Parent.MidiMap.Map(osc, out mapping);

            if (midi != null)
            {
                // log where this message came from
                midi.LogAsOutgoing();
                midi.LogSource(osc.Source); // TODO: log the OSC message as the source?

                // send midi to the devices specified by this mapping
                foreach (var device in Parent.Devices[typeof(MIDI.Hardware.MidiOutputHardwareInterface)])
                {
                    // filter out by destination
                    if (mapping != null && mapping.MidiDestination != null)
                    {
                        if (mapping.MidiDestination.ToLower() != device.Device.Name.ToLower())
                        {
                            continue;
                        }
                    }

                    // send packet
                    device.Driver.Send(midi);
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Sends an event to all implants except the source that this
 /// OSC value was changed.
 /// </summary>
 public void NotifyImplants(OscDataMessage osc)
 {
     new OscImplantEvent()
     {
         Osc = osc
     }.ScheduleTask();
 }
Exemple #3
0
 /// <summary>
 /// Sends this OSC message over all appropriate OSC connections.
 /// </summary>
 public void TransmitOSC(OscDataMessage osc)
 {
     // TODO: need more control on which connections send to from which implants.
     foreach (var remote in Connections.ToArray())
     {
         remote.Send(osc.Address, osc.ValueAsFloat);
     }
 }
Exemple #4
0
        /// <summary>
        /// Called whenever an OSC message is sent by an implant.
        /// </summary>
        public void FromImplant(JavascriptImplant implant, string address, double value)
        {
            var osc = new OscDataMessage();

            osc.Address = address;
            osc.Value   = value;
            osc.Source  = implant.GetSourceName();
            Add(osc);
        }
Exemple #5
0
        /// <summary>
        /// Called when an OSC message is received from the cluster.
        /// </summary>
        public void FromCluster(string address, double[] values)
        {
            var osc = new OscDataMessage();

            osc.Address = address;
            osc.Values  = values;
            osc.Source  = "Cluster";
            Add(osc);
        }
Exemple #6
0
        /// <summary>
        /// Sends the OSC message to all connected cluster nodes.
        /// </summary>
        public void ToCluster(OscDataMessage osc)
        {
            var msg = new OSCClusterMessage()
            {
                OSCAddress = osc.Address,
                OSCValues  = osc.Values
            };

            ClusterClient.Instance.SendAll(msg);
        }
Exemple #7
0
        public void SendMessage(string address, params object[] values)
        {
            var osc = new OscDataMessage();

            osc.Address = address;
            if (values.Length > 0 && values[0] is ArrayInstance)
            {
                var array = values[0] as ArrayInstance;
                osc.Values = new double[array.Length];
                for (var i = 0; i < array.Length; i++)
                {
                    double.TryParse(array[i].ToString(), out osc.Values[i]);
                }
            }
            osc.Source = Parent.GetSourceName();
            Parent.Session.OSC.Add(osc);
        }
Exemple #8
0
        /// <summary>
        /// Maps to a MIDI message if it can, or returns null.
        /// </summary>
        /// <param name="osc">The OSC message to map</param>
        /// <param name="mapping">The mapping used to generate this packet.</param>
        public MidiMessage Map(OscDataMessage osc, out OscToMidiMap mapping)
        {
            // find a mapping that can convert this osc
            mapping = FindMapping(osc.Address, osc.Source);
            if (mapping == null)
            {
                return(null);
            }

            // build midi
            var ret = new MidiMessage();

            ret.Type  = mapping.MidiType;
            ret.Pitch = mapping.GetMidiNote(osc.Address);
            ret.Value = mapping.GetMidiValue(osc.Value);
            return(ret);
        }
Exemple #9
0
        /// <summary>
        /// Forwards along an OSC message from any source.
        /// </summary>
        public void Add(OscDataMessage osc)
        {
#warning all this routing should be handled by the kernel, not just NotifyImplants


            // add to log when enabled
            if (LoggingEnabled)
            {
                Log.Add(new OscLog()
                {
                    Source = osc.Source, Message = osc
                });
            }

            // forward the OSC message to all other subsystems
            OscToMidi(osc);
            TransmitOSC(osc);
            if (osc.Source != "Cluster")
            {
                ToCluster(osc);
            }
            NotifyImplants(osc);
        }