Skip to content

Commit

Permalink
Changes media recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Solomon committed Feb 9, 2022
1 parent ca6343f commit 6611a8b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.6.8] - 2022-01-03

### Added

- Better MIDI out functionality (@TristanCacqueray).
- Allows media recorder to output blob.

## [0.6.7] - 2022-01-03

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "purescript-wags",
"version": "0.6.7",
"version": "0.6.8",
"description": "Web Audio Graphs as a Stream",
"scripts": {
"build": "spago build",
Expand Down
1 change: 1 addition & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
, "unsafe-reference"
, "variant"
, "web-events"
, "web-file"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs" ]
Expand Down
4 changes: 2 additions & 2 deletions src/WAGS/Interpret.js
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ exports.isTypeSupported = function (mimeType) {
// of being set
// if it is set in a loop, then there will effectively be no recording, as it will only capture the
// last couple milliseconds of the loop
exports.mediaRecorderToUrl = function (mimeType) {
exports.mediaRecorderToBlob = function (mimeType) {
return function (handler) {
return function (mediaRecorder) {
return function () {
Expand All @@ -1728,7 +1728,7 @@ exports.mediaRecorderToUrl = function (mimeType) {

mediaRecorder.onstop = function () {
var blob = new Blob(chunks, { type: mimeType });
handler(URL.createObjectURL(blob))();
handler(blob)();
chunks = null;
};
};
Expand Down
8 changes: 7 additions & 1 deletion src/WAGS/Interpret.purs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ module WAGS.Interpret
, makeTriangleOsc
, makeWaveShaper
, mediaRecorderToUrl
, mediaRecorderToBlob
, makeInput
, makeTumultWithDeferredGraph
, makeTumult
Expand Down Expand Up @@ -122,6 +123,7 @@ module WAGS.Interpret

import Prelude

import Control.Bind (bindFlipped)
import Control.Plus (empty)
import Control.Promise (Promise, toAffE)
import Data.Array as Array
Expand Down Expand Up @@ -159,6 +161,8 @@ import WAGS.Tumult.Reconciliation (reconcileTumult)
import WAGS.Util (class ValidateOutputChannelCount)
import WAGS.WebAPI (AnalyserNode, AnalyserNodeCb, BrowserAudioBuffer, BrowserFloatArray, BrowserMediaElement, BrowserMicrophone, BrowserPeriodicWave, MediaRecorder, MediaRecorderCb)
import WAGS.WebAPI as WebAPI
import Web.File.Blob (Blob)
import Web.File.Url (createObjectURL)

foreign import getFFTSize :: WebAPI.AnalyserNode -> Effect Int

Expand Down Expand Up @@ -200,7 +204,9 @@ foreign import stopMediaRecorder :: WebAPI.MediaRecorder -> Effect Unit
-- | ```purescript
-- | mediaRecorderToUrl "audio/ogg" setAudioTagUrlToThisContent recorder
-- | ```
foreign import mediaRecorderToUrl :: String -> (String -> Effect Unit) -> WebAPI.MediaRecorder -> Effect Unit
foreign import mediaRecorderToBlob :: String -> (Blob -> Effect Unit) -> WebAPI.MediaRecorder -> Effect Unit
mediaRecorderToUrl :: String -> (String -> Effect Unit) -> WebAPI.MediaRecorder -> Effect Unit
mediaRecorderToUrl s cb mr = flip (mediaRecorderToBlob s) mr (bindFlipped cb <<< createObjectURL)

-- | Is this MIME type supported by this browser.
foreign import isTypeSupported :: String -> Effect Boolean
Expand Down

0 comments on commit 6611a8b

Please sign in to comment.