Getting Started

Creating a Scala.js Project

In order to use Sounds of Scala you will need to create a Scala.js project.

There are a number of ways to create a Scala.js project for use with Sounds of Scala. At some point you can expect to find a giter8 template here which will do this all for you but for now you can use one of the following methods.


Scala.js with Vite

sbt new scala-js/vite.g8

Once you have the created the project from the giter8 template bump the minimum versions of the following:

In project/build.properties:

sbt.version=1.10.0

In build.sbt

 scalaVersion := "3.3.3"
 "org.scala-js" %%% "scalajs-dom" % "2.8.0"

And in project/plugins.sbt the sbt-scalajs plug in.

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0")

Scala.js with Tyrian

sbt new PurpleKingdomGames/tyrian.g8

Scala.js docs

Scala.js Docs And then follow this guide to add Scala

A Quick Project Scaffold using Scala.js & Vite

Here is an example of a simple Scala.js project using the Vite template:

You can use this to get started with your own project quickly, and simply start using the Sounds of Scala library from within the firstMusicProgram method.

import cats.effect.{IO, Ref}
import cats.effect.unsafe.implicits.global
import org.scalajs.dom
import org.scalajs.dom.{AudioContext, document}
import org.soundsofscala.models.*
import org.soundsofscala.transport.Sequencer

@main
def helloWorld(): Unit =

  val homeDiv = document.createElement("div")

  val heading = document.createElement("h1")
  heading.textContent = "My First Music App"

  val button = document.createElement("button").asInstanceOf[dom.html.Button]
  button.classList.add("button")
  button.textContent = "▶️"
  button.onclick = _ =>
    given AudioContext = new AudioContext()
    firstMusicProgram().unsafeRunAndForget()

  homeDiv.appendChild(heading)
  homeDiv.appendChild(button)
  dom.document.querySelector("#app").append(homeDiv)

def firstMusicProgram(): AudioContext ?=> IO[Unit] = ???
  
  // TODO: Your code

Next Step: Playing a test song