Skip to content

Commit

Permalink
Upgrade to PS 0.15
Browse files Browse the repository at this point in the history
The library and example have been upgraded.  Not the tests - test-unit
is not available.

The library no longer builds simply with Bower after the replacement of
affjax with affjax-web. Spago is fine, though.
  • Loading branch information
newlandsvalley committed May 7, 2022
1 parent 520a6e8 commit 3c0d909
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 34 deletions.
20 changes: 10 additions & 10 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
"url": "https://github.com/newlandsvalley/purescript-soundfonts.git"
},
"dependencies": {
"purescript-prelude": "^5.0.1",
"purescript-affjax": "^12.0.0",
"purescript-parallel": "^5.0.0",
"purescript-argonaut-core": "^6.0.0",
"purescript-encoding": "^0.0.7",
"purescript-b64": "^0.0.7",
"purescript-midi": "^3.1.0"
"purescript-prelude": "^6.0.0",
"purescript-affjax-web": "^1.0.0",
"purescript-parallel": "^6.0.0",
"purescript-argonaut-core": "^7.0.0",
"purescript-encoding": "^0.0.8",
"purescript-b64": "^0.0.8",
"purescript-midi": "^4.0.0"
},
"devDependencies": {
"purescript-psci-support": "^5.0.0",
"purescript-psci-support": "^6.0.0",
"purescript-test-unit": "^16.0.0",
"purescript-console": "^5.0.0",
"purescript-node-fs-aff": "^7.0.0"
"purescript-console": "^6.0.0",
"purescript-node-fs-aff": "^9.0.0"
}
}
8 changes: 7 additions & 1 deletion example.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ let conf = ./spago.dhall

in conf // {
sources = conf.sources # [ "example/src/**/*.purs" ],
dependencies = conf.dependencies # [ "datetime" ]
dependencies = conf.dependencies # [ "datetime"
, "newtype"
, "unsafe-coerce"
, "web-dom"
, "web-events"
, "web-html"
]

}
17 changes: 16 additions & 1 deletion example/dist/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
<!doctype html>
<html>
<body>
<h1>PureScript SoundFonts Example</h1>
<style>
.button {
color: white;
border-radius: 12px;
padding: 5px 22px;
text-align: center;
font-size: 16px
}
.play-button {
background-color: green;
}
</style>
<div id="app">
<h3>Play the SoundFonts example</h3>
<button id="play" class="button play-button">PLAY</button>
</div>
<script src="purescript-soundfonts.js"></script>
</body>
</html>
35 changes: 27 additions & 8 deletions example/src/Main.purs
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
module Example.Main where

import Prelude (bind, ($), (*))
import Prelude (Unit, bind, discard, map, pure, unit, ($), (*), (>>=))
import Effect (Effect)
import Effect.Class (liftEffect)
import Effect.Aff (Fiber, launchAff, delay)
import Effect.Exception (throw)
import Data.Time.Duration (Milliseconds(..))
import Data.Maybe (Maybe(..))
import Data.Newtype (wrap)
import Audio.SoundFont (MidiNote
, loadRemoteSoundFonts
, loadPianoSoundFont
, loadInstrument
, loadInstruments
, playNote
, playNotes)
import Data.Midi.Instrument (InstrumentName(..))
import Web.DOM.ParentNode (querySelector)
import Web.Event.EventTarget (EventTarget, addEventListener, eventListener)
import Web.HTML (window)
import Web.HTML.HTMLDocument (toParentNode)
import Web.HTML.Window (document)
import Unsafe.Coerce (unsafeCoerce)

note :: Int -> Int -> Number -> Number -> Number -> MidiNote
note channel id timeOffset duration gain =
Expand All @@ -39,10 +45,23 @@ notesSample channel =

-- | load remote fonts example

main :: Effect (Fiber Number)
main = launchAff $ do
main :: Effect Unit
main = do
-- a user gesture is required before the browser is allowed to use web-audio
doc <- map toParentNode (window >>= document)
play <- querySelector (wrap "#play") doc
case play of
Just e -> do
el <- eventListener \_ -> playExample
addEventListener (wrap "click") el false (unsafeCoerce e :: EventTarget)
Nothing -> throw "No 'play' button"
pure unit

playExample :: Effect (Fiber Number)
playExample = launchAff $ do
instruments <- loadRemoteSoundFonts [Marimba, AcousticGrandPiano, TangoAccordion]

_ <- delay (Milliseconds $ 1000.0)
da <- liftEffect $ playNote instruments noteSampleA
_ <- delay (Milliseconds $ 1000.0 * da)
db <- liftEffect $ playNote instruments noteSampleC
Expand All @@ -55,7 +74,7 @@ main = launchAff $ do

{-
-- | load local piano font example
main :: ∀ eff.
pianoExample :: ∀ eff.
Eff
( ajax :: AJAX
, au :: AUDIO
Expand All @@ -68,7 +87,7 @@ main :: ∀ eff.
)
Number
)
main = launchAff $ do
pianoExample = launchAff $ do
-- instrument <- loadInstrument (Just "soundfonts") "acoustic_grand_piano"
instrument <- loadPianoSoundFont "soundfonts"
let
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
"scripts": {
"build": "spago build",
"test": "spago -x ./test.dhall test",
"pulp-build": "pulp build",
"pulp-test": "pulp test",
"example" : "spago -x ./example.dhall bundle-app --main Example.Main --to example/dist/purescript-soundfonts.js"
},
"devDependencies": {
"pulp": "^15.0.0",
"purescript": "^0.14.7",
"purescript-psa": "^0.6.0"
"pulp": "^16.0.0",
"purescript": "^0.15.0",
"purescript-psa": "^0.6.0",
"spago": "0.20.9"
}
}
27 changes: 24 additions & 3 deletions packages.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,28 @@ in upstream
-------------------------------
-}
let upstream =
https:https://github.com/purescript/package-sets/releases/download/psc-0.14.7-20220321/packages.dhall
sha256:dff91304260c1196273badf7d8141e66ab16bed147b95aa175dd8a84ec87d58f
https:https://github.com/purescript/package-sets/releases/download/psc-0.15.0-20220506/packages.dhall
sha256:f83b68ff07cf6557e82379e749118e6ff11eecc6be5754540aae855cd1e46917

in upstream
in upstream
with midi =
{ dependencies =
[ "arrays"
, "control"
, "effect"
, "either"
, "foldable-traversable"
, "integers"
, "lists"
, "maybe"
, "ordered-collections"
, "prelude"
, "signal"
, "string-parsers"
, "strings"
, "tuples"
, "unfoldable"
]
, repo = "https://github.com/newlandsvalley/purescript-midi.git"
, version = "v4.0.0"
}
1 change: 1 addition & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ You can edit this file as you like.
, dependencies =
[ "aff"
, "affjax"
, "affjax-web"
, "argonaut-core"
, "arraybuffer-types"
, "arrays"
Expand Down
10 changes: 5 additions & 5 deletions src/Audio/SoundFont.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ var sf = function() {
};
}();

exports.isWebAudioEnabled = sf.isWebAudioEnabled;
exports.canPlayOgg = sf.canPlayOgg;
exports.setNoteRing = sf.setNoteRing;
exports.decodeAudioBufferImpl = sf.decodeAudioBufferImpl;
exports.playFontNote = sf.playFontNote;
export var isWebAudioEnabled = sf.isWebAudioEnabled;
export var canPlayOgg = sf.canPlayOgg;
export var setNoteRing = sf.setNoteRing;
export var decodeAudioBufferImpl = sf.decodeAudioBufferImpl;
export var playFontNote = sf.playFontNote;
2 changes: 1 addition & 1 deletion src/Audio/SoundFont.purs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Audio.SoundFont (
, instrumentChannels
) where

import Affjax (defaultRequest, request)
import Affjax.Web (defaultRequest, request)
import Affjax.ResponseFormat as ResponseFormat
import Audio.SoundFont.Decoder (midiJsToNoteMap, debugNoteIds)
import Audio.SoundFont.Gleitz (RecordingFormat(..), SoundFontType(..), gleitzUrl)
Expand Down

0 comments on commit 3c0d909

Please sign in to comment.