Skip to content

Instantly share code, notes, and snippets.

@gourlaysama
Last active August 15, 2016 16:54
Show Gist options
  • Save gourlaysama/4da60db88cf3f2392402f00bfb825543 to your computer and use it in GitHub Desktop.
Save gourlaysama/4da60db88cf3f2392402f00bfb825543 to your computer and use it in GitHub Desktop.
Midi access in scala.js
import dom.raw.Navigator
@native
trait MidiNavigator extends Navigator {
def requestMIDIAccess(): MidiAccess = js.native
}
object MidiNavigator {
implicit def midinavigator(mn: Navigator): MidiNavigator =
mn.asInstanceOf[MidiNavigator]
}
@native
trait MidiAccess extends js.Object {
// whatever is in the MIDIAccess object
}
import MidiNavigator._
object Midi {
import scala.scalajs.js.DynamicImplicits.truthValue
def apply(): Option[MidiAccess] =
if (js.Dynamic.global.window.navigator.requestMIDIAccess)
Some(dom.window.navigator.requestMIDIAccess())
else
None
}
object ScalaJSExample extends js.JSApp {
def main(): Unit = {
if(Midi().isDefined){
println("Yeah")
}else{
println("arf")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment