Skip to content

Commit

Permalink
Purescript 0.14.0 support
Browse files Browse the repository at this point in the history
Builds with spago, not with pulp.
  • Loading branch information
newlandsvalley committed Mar 1, 2021
1 parent 8e4709e commit a191d0b
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 50 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 10 additions & 12 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
3 changes: 1 addition & 2 deletions packages.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ You can edit this file as you like.
, dependencies =
[
, "effect"
, "generics-rep"
, "integers"
, "lists"
, "prelude"
Expand Down
6 changes: 3 additions & 3 deletions src/Data/Midi.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions test/Instrument.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
42 changes: 25 additions & 17 deletions test/Parser.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit a191d0b

Please sign in to comment.