/// <summary> /// Constructor creates the virual grid for the XY hardware. /// </summary> public MidiXYHardwareInterface(MappedMidiDevice mapping) : base(mapping) { CreateMappers(); Grid = new VirtualGrid((int x, int y, int value) => { if (XYMapper == null) { return(null); } if (mapping == null) { return(null); } // TODO: gonna need to tell the virtual grid to refresh whenever the mapping changes! MidiMessage msg = new MidiMessage(); if (XYMapper.ConvertXY(x, y, out msg.Type, out msg.Number)) { msg.Velocity = value; msg.LogSource(LastSourceName); return(new MidiIndicatorAction() { Driver = mapping.Driver, Message = msg }.ScheduleTask()); } return(null); }, 64, 64, 9, 9); // TODO: maybe have more reasonable defaults? }
/// <summary> /// Called only by the kernel /// </summary> internal void TriggerFromKernel(ImplantEvent e) { MappedMidiDevice device = e.Hardware; // allow event interception if (ImplantEventTriggered != null) { ImplantEventTriggered(this, e); } // OSC events are special. they are delievered to all // implants except their source // TODO: likely need an OSC registration system so only // implants that have registered for a specific OSC address // will get the message if (e is OscImplantEvent) { var osc = e as OscImplantEvent; if (osc.Osc != null) { foreach (var implant in Items.ToArray()) { if (implant.Active && implant.Running) { if (implant.GetSourceName() != osc.Osc.Source) { implant.Trigger(e); } } } } return; } // determine which implants are to receive the event if (device == null || SendToAllEvents(e)) { // send these events to all implants untranslated // TODO: how do we deal with visible here? foreach (var implant in Items.ToArray()) { if (implant.Active && implant.Running) { implant.Trigger(e); } } } else { // send translated event to each implant. var targets = GetImplantsByPhysicalAddress(device, e, true); foreach (var implant in targets.Keys) { implant.Trigger(targets[implant]); } } }
/// <summary> /// Creates a new instance of a hardware interface from a name /// returned from the Available dictionary. /// </summary> public static MidiHardwareInterface CreateInstance(string name, MappedMidiDevice mapping) { MidiHardwareInterface mhi = null; if (_availableInstances.TryGetValue(name, out mhi)) { return(CreateInstance(mhi.GetType(), mapping)); } return(null); }
/// <summary> /// Creates a new MidiHardwareInterface from just a type. /// </summary> private static MidiHardwareInterface CreateInstance(Type t, MappedMidiDevice mapping = null) { try { if (t.IsAbstract) { return(null); } var constructor = t.GetConstructor(new Type[] { typeof(MappedMidiDevice) }); return(constructor.Invoke(new object[] { mapping }) as MidiHardwareInterface); } catch (Exception ex) { Session.UserSession.Current.Console.Add(ex.ToString(), "MidiHardwareInterface"); return(null); } }
public MidiOutputHardwareInterface(MappedMidiDevice device) : base(device) { }
public LaunchPadHardwareInterface(MappedMidiDevice mapping) : base(mapping) { }
public MidiClockOutputHardwareInterface(MappedMidiDevice mapped) : base(mapped) { }
/// <summary> /// Sets up the IO for the subclass. /// </summary> public MidiHardwareInterface(MappedMidiDevice mapping) { this.Mapping = mapping; }
/// <summary> /// Maps a device to a new usage. /// </summary> public void Map(MidiDevice device, string hardwareInterface) // MidiDeviceMapping map) { lock (Mapped) { bool changed = false; MappedMidiDevice mapping = null; // replace the "empty" marker with null if (hardwareInterface == "---") { hardwareInterface = null; } try { // either find an existing mapping to change or create a new one mapping = GetMapping(device); if (mapping == null) { mapping = new MappedMidiDevice() { Device = device }; Mapped.Add(mapping); } // update mapping if (hardwareInterface != null) { if (mapping.Hardware == null || mapping.Hardware.Name != hardwareInterface) { changed = true; } } else { changed = mapping.Hardware != null; } // SIMULATOR TEMP HACK // TODO: fully integrate this into the midi driver pipeline if (device is LaunchPadSimulator) { // assign virtual driver if (mapping.Driver == null) { mapping.Driver = new LPToolKit.Platform.VirtualMidiDriver(); mapping.Driver.SelectedDevice = device; } return; } // END SIMULATOR TEMP HACK // ensure appropriate driver is setup bool needsDriver = hardwareInterface != null; //map != MidiDeviceMapping.None; if (needsDriver) { // create and setup the driver if (mapping.Driver == null) { mapping.Driver = MidiDriver.CreatePlatformInstance(); } mapping.Driver.SelectedDevice = mapping.Device; } else { // destroy any used driver if we're not using the device if (mapping.Driver != null) { mapping.Driver.SelectedDevice = null; } mapping.Hardware.Clear(); mapping.Hardware = null; mapping.Driver = null; Mapped.Remove(mapping); } // setting hardware specific settings if (hardwareInterface != null) { mapping.Hardware = MidiHardwareTypes.CreateInstance(hardwareInterface, mapping); } else { mapping.Hardware = null; } // destroy any other drivers mapped to this device foreach (var other in Mapped.ToArray()) { if (other == mapping) { continue; } if (other.Device == mapping.Device) { // shut down duplicate device if (mapping.Driver != null) { mapping.Driver.SelectedDevice = null; } mapping.Hardware.Clear(); mapping.Hardware = null; mapping.Driver = null; Mapped.Remove(other); } } } finally { // warn about device change new DeviceChangeImplantEvent() { Mapping = mapping }.ScheduleTask(); } } }
public GenericKeyboardHardwareInterface(MappedMidiDevice device) : base(device) { }
/// <summary> /// Returns the list of all Implants that are mapped to a given /// device coordinate so we never waste time sending events /// to implants that won't use them. /// </summary> private Dictionary <JavascriptImplant, ImplantEvent> GetImplantsByPhysicalAddress(MappedMidiDevice device, ImplantEvent e, bool visibleOnly = false) { // TODO: need to decide how to deal with modes here var target = visibleOnly ? Visible.ToArray() : Items.ToArray(); var ret = new Dictionary <JavascriptImplant, ImplantEvent>(); foreach (var implant in target) { if (implant.Active == false) { continue; } if (implant.Running == false) { continue; } int vx, vy; if (implant.ActiveArea.GetVirtualAddress(device, e.X, e.Y, out vx, out vy)) { // TODO: scroll these?!!! // clone this event with a virtual address for this implant var implantEvent = e.Clone(); implantEvent.X = vx; implantEvent.Y = vy; ret.Add(implant, implantEvent); } } return(ret); }