1.0.245 • Published 6 years ago

@musical-patterns/performer v1.0.245

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Build Status

Musical Patterns - Performer

Given a pattern compiled by the @musical-patterns/compiler, hooks it up to the Web Audio and WebXR APIs and gives you the power to play it (and pause it, etc.)

usage

npm i @musical-patterns/performer

setup

import { setupPerformer, OnUpdate } from '@musical-patterns/performer'

const onUpdate: OnUpdate = time => {
	// do whatever you wanna do with the latest time here, such as update some display
	// note that the time this callback gets called with, if your pattern repeats from some point whenever it reaches the end, will restart to that time (it is not the raw time passed since starting the pattern in your reality; it is the time within the pattern)
}

await setupPerformer({ onUpdate })

This will ensure your browser is ready to start playing!

loading a pattern

import { setPattern, CompiledPattern } from '@musical-patterns/performer'

const compiledPattern: CompiledPattern = {
	// your compiled pattern here
}

await setPattern(compiledPattern)

setPattern only sets what is to be performed. It does not start playing it yet.

starting and stopping

import { play, pause, stop } from '@musical-patterns/performer'

# set paused to true
pause()
# set paused to false
play()
# or set paused to false plus reset the time to 0
await stop()

enabling immersive audio

import { enableImmersiveAudio } from '@musical-patterns/performer'
import { buildVrb } from 'vrb'

const homePosition: Coordinate = [ 5, 4, 3 ]
const onReady: VoidFunction = () => {
	// do whatever you want once the VR device is ready
}
const onNoVr: VoidFunction = () => {
	// do whatever you want once it is determined that your system does not support VR
}

const toggleImmersiveAudioHandler: VoidFunction = enableImmersiveAudio({ vrb, homePosition, onReady, onNoVr })

const toggleImmersiveAudioButton = document.createElement('div')
toggleImmersiveAudioButton.innerText = 'Toggle Immersive Audio'
toggleImmersiveAudioButton.addEventListener('click', toggleImmersiveAudioHandler)
document.body.appendChild(toggleImmersiveAudioButton)

If you have your own instance of Vrb (https://www.npmjs.com/package/vrb) you may inject it here. If you do not, Vrb is what will be used under the hood for WebVR and it will be automatically configured to reasonable defaults for you.

or if you're an eager beaver

If you pass voices to the setup, it will automatically start playing them.

import { compilePattern } from '@musical-patterns/compiler'
import { setupPerformer, CompiledPattern } from '@musical-patterns/performer'
import { pattern } from '@musical-patterns/pattern-houndstoothtopia-theme'

const compiledPattern: CompiledPattern = await compilePattern(pattern)
await setupPerformer({
	compiledPattern,
})

jumping around in time

import { setTime } from '@musical-patterns/performer'

await setTime(14000)

It will keep playing if it was playing already.

1.0.245

6 years ago

1.0.244

6 years ago

1.0.243

6 years ago

1.0.242

6 years ago

1.0.241

6 years ago

1.0.240

6 years ago

1.0.239

6 years ago

1.0.238

6 years ago

1.0.235

6 years ago

1.0.234

6 years ago

1.0.231

6 years ago

1.0.230

6 years ago

1.0.229

6 years ago

1.0.228

6 years ago

1.0.227

6 years ago

1.0.226

6 years ago

1.0.225

6 years ago

1.0.224

6 years ago

1.0.223

6 years ago

1.0.222

6 years ago

1.0.221

6 years ago

1.0.220

6 years ago

1.0.219

6 years ago

1.0.218

6 years ago

1.0.217

6 years ago

1.0.216

6 years ago

1.0.215

6 years ago

1.0.214

6 years ago

1.0.213

6 years ago

1.0.212

6 years ago

1.0.211

6 years ago

1.0.210

6 years ago

1.0.209

6 years ago

1.0.208

6 years ago

1.0.207

6 years ago

1.0.206

6 years ago

1.0.205

6 years ago

1.0.204

6 years ago

1.0.203

6 years ago

1.0.202

6 years ago

1.0.201

6 years ago

1.0.200

6 years ago

1.0.199

6 years ago

1.0.198

6 years ago

1.0.197

6 years ago

1.0.196

6 years ago

1.0.195

6 years ago

1.0.194

6 years ago

1.0.193

6 years ago

1.0.192

6 years ago

1.0.191

6 years ago

1.0.190

6 years ago

1.0.189

6 years ago

1.0.188

6 years ago

1.0.187

6 years ago

1.0.186

6 years ago

1.0.185

6 years ago

1.0.184

6 years ago

1.0.183

6 years ago

1.0.182

6 years ago

1.0.181

6 years ago

1.0.180

6 years ago

1.0.179

6 years ago

1.0.178

6 years ago

1.0.177

6 years ago

1.0.176

6 years ago

1.0.175

6 years ago

1.0.174

6 years ago

1.0.173

6 years ago

1.0.172

6 years ago

1.0.171

6 years ago

1.0.170

6 years ago

1.0.169

6 years ago

1.0.168

6 years ago

1.0.167

6 years ago

1.0.166

6 years ago

1.0.165

6 years ago

1.0.164

6 years ago

1.0.163

6 years ago

1.0.162

6 years ago

1.0.161

6 years ago

1.0.160

6 years ago

1.0.159

6 years ago

1.0.158

6 years ago

1.0.157

6 years ago

1.0.156

6 years ago

1.0.155

6 years ago

1.0.154

6 years ago

1.0.153

6 years ago

1.0.152

6 years ago

1.0.151

6 years ago

1.0.150

6 years ago

1.0.149

6 years ago

1.0.148

6 years ago

1.0.147

6 years ago

1.0.146

6 years ago

1.0.145

6 years ago

1.0.144

6 years ago

1.0.143

6 years ago

1.0.142

6 years ago

1.0.141

6 years ago

1.0.140

6 years ago

1.0.139

6 years ago

1.0.138

6 years ago

1.0.137

6 years ago

1.0.136

6 years ago

1.0.135

6 years ago

1.0.134

6 years ago

1.0.133

6 years ago

1.0.132

6 years ago

1.0.131

6 years ago

1.0.130

6 years ago

1.0.129

6 years ago

1.0.128

6 years ago

1.0.126

6 years ago

1.0.125

6 years ago

1.0.124

6 years ago

1.0.123

6 years ago

1.0.122

6 years ago

1.0.121

6 years ago

1.0.120

6 years ago

1.0.119

6 years ago

1.0.118

6 years ago

1.0.117

6 years ago

1.0.116

6 years ago

1.0.115

6 years ago

1.0.114

6 years ago

1.0.113

6 years ago

1.0.112

6 years ago

1.0.111

6 years ago

1.0.110

6 years ago

1.0.109

6 years ago

1.0.108

6 years ago

1.0.107

6 years ago

1.0.106

6 years ago

1.0.105

6 years ago

1.0.104

6 years ago

1.0.103

6 years ago

1.0.102

6 years ago

1.0.101

6 years ago

1.0.100

6 years ago

1.0.99

6 years ago

1.0.98

6 years ago

1.0.97

6 years ago

1.0.96

6 years ago

1.0.95

6 years ago

1.0.94

6 years ago

1.0.93

6 years ago

1.0.92

6 years ago

1.0.91

6 years ago

1.0.90

6 years ago

1.0.89

6 years ago

1.0.88

6 years ago

1.0.87

6 years ago

1.0.86

6 years ago

1.0.85

6 years ago

1.0.84

6 years ago

1.0.83

6 years ago

1.0.82

6 years ago

1.0.81

6 years ago

1.0.80

6 years ago

1.0.79

6 years ago

1.0.78

6 years ago

1.0.77

6 years ago

1.0.76

6 years ago

1.0.75

6 years ago

1.0.74

6 years ago

1.0.73

6 years ago

1.0.72

6 years ago

1.0.71

6 years ago

1.0.70

7 years ago

1.0.69

7 years ago

1.0.68

7 years ago

1.0.66

7 years ago

1.0.65

7 years ago

1.0.63

7 years ago

1.0.62

7 years ago

1.0.61

7 years ago

1.0.60

7 years ago

1.0.59

7 years ago

1.0.57

7 years ago

1.0.56

7 years ago

1.0.55

7 years ago

1.0.54

7 years ago

1.0.53

7 years ago

1.0.52

7 years ago

1.0.51

7 years ago

1.0.50

7 years ago

1.0.49

7 years ago

1.0.48

7 years ago

1.0.47

7 years ago

1.0.46

7 years ago

1.0.45

7 years ago

1.0.44

7 years ago

1.0.43

7 years ago

1.0.42

7 years ago

1.0.41

7 years ago

1.0.40

7 years ago

1.0.39

7 years ago

1.0.38

7 years ago

1.0.37

7 years ago

1.0.36

7 years ago

1.0.35

7 years ago

1.0.34

7 years ago

1.0.33

7 years ago

1.0.32

7 years ago

1.0.31

7 years ago

1.0.30

7 years ago

1.0.29

7 years ago

1.0.28

7 years ago

1.0.27

7 years ago

1.0.26

7 years ago

1.0.25

7 years ago

1.0.24

7 years ago

1.0.23

7 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago