1 /** 2 * Copyright: Enalye 3 * License: Zlib 4 * Authors: Enalye 5 */ 6 module minuit.util.misc; 7 8 import minuit.device; 9 10 /** 11 * Fetch all output ports' name. 12 * Returns: A list of all the output ports' name 13 */ 14 string[] mnFetchOutputsName() { 15 MnOutputPort[] ports = mnFetchOutputs(); 16 string[] portsName; 17 foreach(port; ports) 18 portsName ~= port.name; 19 return portsName; 20 } 21 22 /** 23 * Fetch all input ports' name. 24 * Returns: A list of all the input ports' name 25 */ 26 string[] mnFetchInputsName() { 27 MnInputPort[] ports = mnFetchInputs(); 28 string[] portsName; 29 foreach(port; ports) 30 portsName ~= port.name; 31 return portsName; 32 } 33 34 /** 35 * Attempt to find a specific output port. 36 * Params: 37 * portName = The name of the port to fetch 38 * Returns: The port associated with the name 39 */ 40 MnOutputPort mnFetchOutput(string portName) { 41 MnOutputPort[] ports = mnFetchOutputs(); 42 foreach(port; ports) 43 if(port.name == portName) 44 return port; 45 return null; 46 } 47 48 /** 49 * Attempt to find a specific input port. 50 * Params: 51 * portName = The name of the port to fetch 52 * Returns: The port associated with the name 53 */ 54 MnInputPort mnFetchInput(string portName) { 55 MnInputPort[] ports = mnFetchInputs(); 56 foreach(port; ports) 57 if(port.name == portName) 58 return port; 59 return null; 60 } 61 62 /** 63 * Open a new output handle to send events to a port. 64 * Params: 65 * portName = The name of the port to open 66 * Returns: A new handle to send midi events or null if the port doesn't exist 67 */ 68 MnOutputHandle mnOpenOutput(string portName) { 69 MnOutputPort[] ports = mnFetchOutputs(); 70 foreach(port; ports) { 71 if(port.name == portName) { 72 return minuit.device.mnOpenOutput(port); 73 } 74 } 75 return null; 76 } 77 78 /** 79 * Open a new input handle to receive events from a port. 80 * Params: 81 * portName = The name of the port to open 82 * Returns: A new handle to receive midi events or null if the port doesn't exist 83 */ 84 MnInputHandle mnOpenInput(string portName) { 85 MnInputPort[] ports = mnFetchInputs(); 86 foreach(port; ports) { 87 if(port.name == portName) { 88 return minuit.device.mnOpenInput(port); 89 } 90 } 91 return null; 92 } 93 94 /** 95 * Open a new output handle to send events to a port. 96 * Params: 97 * portId = The id of the port to open (0: default) 98 * Returns: A new handle to send midi events or null if the port doesn't exist 99 */ 100 MnOutputHandle mnOpenOutput(uint portId = 0) { 101 MnOutputPort[] ports = mnFetchOutputs(); 102 if(portId > ports.length) 103 return null; 104 return minuit.device.mnOpenOutput(ports[portId]); 105 } 106 107 /** 108 * Open a new input handle to receive events from a port. 109 * Params: 110 * portId = The id of the port to open (0: default) 111 * Returns: A new handle to receive midi events or null if the port doesn't exist 112 */ 113 MnInputHandle mnOpenInput(uint portId = 0) { 114 MnInputPort[] ports = mnFetchInputs(); 115 if(portId > ports.length) 116 return null; 117 return minuit.device.mnOpenInput(ports[portId]); 118 }