From a191d0bc746950caf82a1b7abaca2e61dc532a9b Mon Sep 17 00:00:00 2001 From: John Watson Date: Mon, 1 Mar 2021 11:55:58 +0000 Subject: [PATCH] Purescript 0.14.0 support Builds with spago, not with pulp. --- .github/workflows/ci.yml | 51 ++++++++++++++++++++++++++++++++++++++++ .travis.yml | 9 ------- README.md | 10 +++++--- bower.json | 22 ++++++++--------- examples/README.md | 2 +- package.json | 15 ++++++++++++ packages.dhall | 3 +-- spago.dhall | 1 - src/Data/Midi.purs | 6 ++--- test/Instrument.purs | 5 ++-- test/Parser.purs | 42 +++++++++++++++++++-------------- 11 files changed, 116 insertions(+), 50 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml create mode 100644 package.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3ba427a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,51 @@ +name: CI + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up PureScript toolchain + uses: purescript-contrib/setup-purescript@main + + - name: Cache PureScript dependencies + uses: actions/cache@v2 + with: + key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }} + path: | + .spago + output + + - name: Set up Node toolchain + uses: actions/setup-node@v1 + with: + node-version: "12.x" + + - name: Cache NPM dependencies + uses: actions/cache@v2 + env: + cache-name: cache-node-modules + with: + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: Install NPM dependencies + run: npm install + + - name: Build the project + run: npm run build + + - name: Run tests + run: npm run test \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9a0e478..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: node_js -node_js: node -dist: trusty -sudo: required -install: - - npm install -g bower purescript pulp - - bower install -script: - - pulp test diff --git a/README.md b/README.md index 21f1f32..485a680 100644 --- a/README.md +++ b/README.md @@ -18,13 +18,17 @@ On the other hand, you may merely need to parse MIDI events (such as note on or This will attempt to parse an individual event. -## Installation +## To Build - bower install purescript-midi + npm run build + +## To Test + + npm run test ## Examples -See examples. +There are examples in the _examples_ folder, however nearly all of these were developed for earlier releases of PureScript (many using Pux) and will be removed at some stage. Nevertheless they give some idea of how the library may be used. ## Web MIDI Permissions It appears that browsers are becoming stricter about allowing Web MIDI to run from 'untrusted' servers after being notified of security exploits. At the time of writing, both Chrome (see [details](https://www.chromestatus.com/feature/5138066234671104)) and Mozilla require HTTPS connections. diff --git a/bower.json b/bower.json index a4504f0..31ff33b 100644 --- a/bower.json +++ b/bower.json @@ -17,20 +17,18 @@ "url": "https://github.com/newlandsvalley/purescript-midi.git" }, "dependencies": { - "purescript-prelude": "^4.1.1", - "purescript-lists": "^5.4.1", - "purescript-string-parsers": "^5.0.0", - "purescript-integers": "^4.0.0", - "purescript-unicode": "^4.0.1", - "purescript-generics-rep": "^6.1.1", - "purescript-signal": "^10.1.0" + "purescript-prelude": "^5.0.0", + "purescript-lists": "^6.0.0", + "purescript-string-parsers": "^6.0.0", + "purescript-integers": "^5.0.0", + "purescript-signal": "^11.0.3" }, "devDependencies": { - "purescript-psci-support": "^4.0.0", - "purescript-node-fs-aff": "^6.0.0", - "purescript-node-buffer": "^6.0.0", + "purescript-psci-support": "^5.0.0", + "purescript-node-fs-aff": "^7.0.0", + "purescript-node-buffer": "^7.0.0", "purescript-test-unit": "^15.0.0", - "purescript-quickcheck": "^6.1.0", - "purescript-assert": "^4.1.0" + "purescript-quickcheck": "^7.0.0", + "purescript-assert": "^5.0.0" } } diff --git a/examples/README.md b/examples/README.md index be384a1..8fee30e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -12,7 +12,7 @@ see also: [ABC Editor](https://github.com/newlandsvalley/purescript-abc-editor), [PureScript School of Music Editor](https://github.com/newlandsvalley/purescript-school-of-music/tree/master/editor) etc. -### v1.2.0 (PureScript 0.11) +### v1.2.0 (deprecated - PureScript 0.11) * __midifile__ load MIDI from the local file system and then parse it. * __midiurl__ loading MIDI from a URL and then parse it. diff --git a/package.json b/package.json new file mode 100644 index 0000000..95a0eb1 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "private": true, + "scripts": { + "build": "spago build", + "test": "spago -x ./test.dhall test", + "pulp-build": "pulp build", + "pulp-test": "pulp test" + }, + "devDependencies": { + "pulp": "^15.0.0", + "purescript": "^0.14.0", + "purescript-psa": "^0.6.0", + "webpack": "^3.6.0" + } +} diff --git a/packages.dhall b/packages.dhall index 68a4a67..d24232f 100644 --- a/packages.dhall +++ b/packages.dhall @@ -104,8 +104,7 @@ in upstream } ------------------------------- -} - let upstream = - https://github.com/purescript/package-sets/releases/download/psc-0.13.8-20201021/packages.dhall sha256:55ebdbda1bd6ede4d5307fbc1ef19988c80271b4225d833c8d6fb9b6fb1aa6d8 + https://github.com/purescript/package-sets/releases/download/psc-0.14.0/packages.dhall sha256:710b53c085a18aa1263474659daa0ae15b7a4f453158c4f60ab448a6b3ed494e in upstream diff --git a/spago.dhall b/spago.dhall index 7543cf2..c77c7cd 100644 --- a/spago.dhall +++ b/spago.dhall @@ -6,7 +6,6 @@ You can edit this file as you like. , dependencies = [ , "effect" - , "generics-rep" , "integers" , "lists" , "prelude" diff --git a/src/Data/Midi.purs b/src/Data/Midi.purs index 1f735ae..1dd4fe8 100644 --- a/src/Data/Midi.purs +++ b/src/Data/Midi.purs @@ -19,9 +19,9 @@ import Data.List (List) import Data.List.NonEmpty (NonEmptyList) as Nel import Data.Maybe (Maybe) import Data.Generic.Rep -import Data.Generic.Rep.Eq (genericEq) -import Data.Generic.Rep.Ord (genericCompare) -import Data.Generic.Rep.Show (genericShow) +import Data.Eq.Generic (genericEq) +import Data.Ord.Generic (genericCompare) +import Data.Show.Generic (genericShow) -- | A Tick represents a MIDI time increment. See the MIDI Specification, -- | page 135 - delta-time. diff --git a/test/Instrument.purs b/test/Instrument.purs index 2d9e387..ca86981 100644 --- a/test/Instrument.purs +++ b/test/Instrument.purs @@ -3,6 +3,7 @@ module Test.Instrument (instrumentChecksSuite) where import Prelude (Unit, ($), (<$>), discard, map) import Data.List (toUnfoldable) +import Data.Array.NonEmpty (fromNonEmpty) import Data.NonEmpty ((:|)) import Data.Maybe (Maybe(..)) import Control.Monad.Free (Free) @@ -27,12 +28,12 @@ instance testGleitzmanarb :: Arbitrary TestGleitzman where arbInstrumentName :: Gen InstrumentName arbInstrumentName = - elements $ + elements $ fromNonEmpty $ AcousticGrandPiano :| toUnfoldable instrumentNames arbGleitzmanName :: Gen String arbGleitzmanName = - elements $ + elements $ fromNonEmpty $ "acoustic_grand_piano" :| toUnfoldable gleitzmanNames arbTestInstrument :: Gen TestInstrument diff --git a/test/Parser.purs b/test/Parser.purs index c6a7923..522d80d 100644 --- a/test/Parser.purs +++ b/test/Parser.purs @@ -5,11 +5,12 @@ import Data.Midi import Control.Monad.Free (Free) import Data.Array (singleton, fromFoldable) as Array +import Data.Array.NonEmpty (NonEmptyArray, fromNonEmpty) import Data.Char (fromCharCode) import Data.Either (Either(..)) import Data.List (List(..), (:), fromFoldable, toUnfoldable) -import Data.List.NonEmpty (NonEmptyList, cons, fromList, singleton) -import Data.NonEmpty (NonEmpty, (:|)) +import Data.List.NonEmpty (NonEmptyList(..), cons, fromList, singleton) +import Data.NonEmpty ((:|)) import Data.Maybe (Maybe(..), fromMaybe) import Data.Midi.Generate as Generate import Data.Midi.Parser (parse, parseMidiEvent, parseMidiMessage) @@ -80,7 +81,7 @@ arbTrackFormat trackCount = arbSysExFlavour :: Gen SysExFlavour arbSysExFlavour = - elements $ + elements $ fromNonEmpty $ F0 :| [ F0, F7 ] -- | because velocity 0 means NoteOff, we don't want to issue @@ -269,11 +270,16 @@ arbKeySignature = -- very arbitrary arbitraries! arbTimeSignature :: Gen Event arbTimeSignature = - TimeSignature - <$> (chooseInt 1 100) -- numerator - <*> elements (4 :| [1,2,4,8,16,32,64,128 ]) -- denominator - <*> (pure 24) -- clock count - <*> (chooseInt 1 64) -- 32nd notes per quarter note + let + powersOfTwo :: NonEmptyArray Int + powersOfTwo = + fromNonEmpty (4 :| [1,2,4,8,16,32,64,128 ]) + in + TimeSignature + <$> (chooseInt 1 100) -- numerator + <*> elements powersOfTwo -- denominator + <*> (pure 24) -- clock count + <*> (chooseInt 1 64) -- 32nd notes per quarter note arbSequencerSpecific :: Gen Event arbSequencerSpecific = @@ -334,19 +340,20 @@ weightedSysExEvent :: Generate.Context -> Tuple Number (Gen Event) weightedSysExEvent ctx = Tuple 20.0 $ arbSysEx ctx -commonEvents :: NonEmpty Array (Gen Event) +commonEvents :: NonEmptyArray (Gen Event) commonEvents = - arbNoteOn :| channelEvents + fromNonEmpty $ arbNoteOn :| channelEvents -allEvents :: Generate.Context -> NonEmpty Array (Gen Event) +allEvents :: Generate.Context -> NonEmptyArray (Gen Event) allEvents ctx = - arbNoteOn :| (channelEvents <> Array.singleton (arbSysEx ctx) <> metaEvents) + fromNonEmpty $ arbNoteOn :| (channelEvents <> Array.singleton (arbSysEx ctx) <> metaEvents) -weightedEvents :: Generate.Context -> NonEmpty List (Tuple Number (Gen Event)) +weightedEvents :: Generate.Context -> NonEmptyList (Tuple Number (Gen Event)) weightedEvents ctx = - (Tuple 1.0 arbNoteOn) - :| - ( weightedChannelEvents + NonEmptyList $ + (Tuple 1.0 arbNoteOn) + :| + ( weightedChannelEvents <> ( (weightedSysExEvent ctx) : Nil) <> weightedMetaEvents ) @@ -374,7 +381,8 @@ arbTestMessage = arbTrack :: Gen Track arbTrack = do - count <- chooseInt 0 256 + count <- chooseInt 0 100 + -- this doesn't seem to terminate when testing with spago -- count <- chooseInt 0 250 Track <$> listOf count arbMessage