Last active
August 15, 2016 16:54
-
-
Save gourlaysama/4da60db88cf3f2392402f00bfb825543 to your computer and use it in GitHub Desktop.
Midi access in scala.js
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
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