This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class McpDriverManager(private val presenter: MidiControllerContract.Presenter, driver: Driver) { | |
companion object { | |
val mixerAdcStartChannel = 10 | |
} | |
private val keys: DoubleArray = doubleArrayOf(Key.C0, Key.Cs0, Key.D0, Key.Ds0, Key.E0, Key.F0, Key.Fs0, Key.G0) | |
private val mixerMcpDriver: McpDriver = McpDriver(driver.getSpio0(), driver.getSclk(), driver.getMosi(), driver.getMiso()) | |
private val mixerMidiPots: MutableList<MidiPot> = mutableListOf() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MidiPot(private val mcpDriver: McpDriver, | |
private val presenter: MidiControllerContract.Presenter, | |
private val analogChannel: Int, | |
val midiChannel: Byte, | |
val key: Byte) : Listener { | |
override fun onChange(read: Int) { | |
presenter.onControlChange(this, read.toByte()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MidiController.kt (mobile) | |
class MidiController( | |
context: Context, | |
private val midiManager: MidiManager = context.getSystemService(Context.MIDI_SERVICE) as MidiManager, | |
private val midiDeviceMonitor: MidiDeviceMonitor = MidiDeviceMonitor(context, midiManager) | |
) : AndroidViewModel(context.applicationContext as Application) { | |
private var midiInputPort: MidiInputPort? = null | |
// ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MainActivity.kt (mobile) | |
class MidiPayloadCallback(private val midiController: MidiController) : PayloadCallback() { | |
override fun onPayloadReceived(endpointId: String?, payload: Payload?) { | |
val data = payload?.asBytes() | |
if (data is ByteArray && data.size == 4) { | |
val bytes = byteArrayOf((data[0] + data[1]).toByte(), data[2], data[3]) | |
midiController.send(bytes, System.nanoTime()) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MaintActivity.kt (things) | |
override fun sendPayload(endpointId: String, wrapper: MidiEventWrapper) { | |
Nearby.Connections.sendPayload( | |
googleApiClient, | |
endpointId, | |
Payload.fromBytes(byteArrayOf(wrapper.type(), wrapper.channel(), wrapper.note(), wrapper.pressure()))) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lastMidiButtonPressed: MidiButton? = null | |
override fun onPressed(button: MidiButton, pressed: Boolean) { | |
if (endpoint != null) { | |
if (pressed) { | |
if (lastMidiButtonPressed != button) { | |
view.sendPayload(endpoint!!, MidiEventWrapper( | |
MidiEventType.STATUS_NOTE_ON, button.channel, DEFAULT_NOTE, DEFAULT_VELOCITY)) | |
lastMidiButtonPressed = button | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MidiPot constructor(private val mcpController: MCP3008.Controller, | |
private val presenter: MidiControllerContract.Presenter, | |
private val analogChannel: Int, | |
private val midiChannel: Byte) : MCP3008.Listener { | |
override fun onChange(read: Int) { | |
presenter.onControlChange(read, midiChannel) | |
} | |
fun start() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MidiControls(private val presenter: MidiControllerContract.Presenter) { | |
private lateinit var buttonInputDriverOne: ButtonInputDriver | |
private lateinit var buttonInputDriverTwo: ButtonInputDriver | |
private lateinit var midiPotOne: MidiPot | |
private lateinit var mcpController: MCP3008.Controller | |
val midiButtons: MutableList<MidiButton> = mutableListOf() |