GithubHelp home page GithubHelp logo

linkai101 / muse Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hackclub/muse

0.0 0.0 0.0 1.02 MB

๐ŸŽธ a simple language for jamming!

Home Page: https://muse.hackclub.com

License: MIT License

HTML 3.28% JavaScript 84.29% CSS 12.43%

muse's Introduction

๐ŸŽธ Muse: a simple language for jamming!

Launch the Muse Editor โ†’

Muse is a simple language embedded in a JavaScript environment.

This is a documentation page. For some tips on composing with Muse check out this workshop. A video introducing Muse can also be found here.

To create a song create a muse and pass in your code.

createMuse().play`a4+ ;- [ c5 ; e5 ] x 4`

The language has notes: a, a#, b, c, c#, d, d#, e, f, f#, g & g# with an optional number suffix (from 1 to 10) for pitch. For example:

a4

You can lengthen notes by appending a +:

a4+
a4++
a4+++

or shorten them by appending a -:

a4-
a4--
a4---

Each + or - corresponds to a power of 2.

A pause is ; which can also be lengthened or shortened.

So an arpeggio is:

a4 ; c5 ; e5

And a chord is:

a4 c5 e5

A group is denoted with brackets [ ]:

[ a4 c5 e5 ]++

To repeat something use x and some number:

[ a4 c5 e5 ; ] x 4

createMuse also takes some optional arguments for beats per minute and wave type:

createMuse({ bpm: 10, type: "sine" }) // type can be sine | sawtooth | triangle | square

You can also use samples that are listed to the right of the editor:

createMuse().play`bubbles ; bubbles -`

To play multiple tracks just call play multiple times:

const muse = createMuse()
muse.play`[ a4 ; e4 ; d5 ; ]`
muse.play`[ a5 ; e5 ; d6 ; ]`

Offset notes up by half steps with a ^:

const muse = createMuse()
muse.play`[ a4 ; e4 ; d5 ; ]`
muse.play`[ a4 ; e4 ; d5 ; ] ^ 3`

Offset notes down by half steps with a _.

const muse = createMuse()
muse.play`[ a4 ; e4 ; d5 ; ]`
muse.play`[ a4 ; e4 ; d5 ; ] _ 3`

You can also bind functions to keys with the bindKey function. The key will correspond to the keydown event key and the value to the callback function.

Here is an example keyboard with the bindKey function:

const key = 4
const type = "triangle" // sine | triangle | square | sawtooth

const a = () => createMuse({ type }).play`a${key}`
const s = () => createMuse({ type }).play`b${key}`
const d = () => createMuse({ type }).play`c${key+1}`
const f = () => createMuse({ type }).play`d${key+1}`
const g = () => createMuse({ type }).play`e${key+1}`
const h = () => createMuse({ type }).play`f#${key+1}`
const j = () => createMuse({ type }).play`g${key+1}`
const k = () => createMuse({ type }).play`a${key+1}`
const l = () => createMuse({ type }).play`b${key+1}`

// these keys get bound
bindKeys({ 
  a, 
  s, 
  d, 
  f, 
  g, 
  h, 
  j, 
  k, 
  l 
})

The console on the right of the editor just logs whatever was played.

If the playback is becoming choppy, just refresh the browser. Your current project won't be deleted.

Advanced

Create your own custom modifier by interpolating in a function:

const muse = createMuse();
muse.play`[ a4 ; e4 ; d5 ; ]  ${x => x.reverse()}`

The function will be called with the preceding notes in a compiled array form: [symbol, beats].

An array in this form can be returned or passed in directly.

This custom modifier with shorten pauses and lengthen other notes:

const customModifier = x => x.map( ([sym, dur]) => sym === ";" 
  ? [sym, dur * .2] 
  : [sym, dur * 2]
)

createMuse().play`
  [ a4 ; e4 ; d5 ; c5 ; e4 ; d5 ; ] ${customModifier}
`

Importing Muse

The Muse class can be imported through modules. For example:

import { Muse } from "https://muse.hackclub.dev/exports.js";
import confetti from 'https://cdn.skypack.dev/canvas-confetti';

const samples = {
  "confetti": (ctx, duration) => confetti()
}
const muse = new Muse({ samples });
muse.play`
  a4; c5 confetti; e5;
  confetti ;
`

Acknowledgements

Code editor created using the amazing CodeMirror.

Audio samples come from Patatap, a delightful interactive art piece.

muse's People

Contributors

leomcelroy avatar maxwofford avatar sampoder avatar tevan-goldberg avatar zachlatta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.