Giter Site home page Giter Site logo

scribbletune / scribbletune Goto Github PK

View Code? Open in Web Editor NEW
3.7K 89.0 238.0 2.15 MB

Create music with JavaScript

Home Page: https://scribbletune.com/

License: MIT License

JavaScript 3.28% TypeScript 96.72%
javascript chords midi scale music nodejs webaudio webaudioapi ableton-live ableton

scribbletune's Introduction

SCRIBBLETUNE

Build Status Try scribbletune on RunKit

Use simple JavaScript Strings and Arrays to generate rhythms and musical patterns. Directly use the names of scales or chords in your code to get arrays which you can mash up using Array methods in ways you hadn't imagined before! Create clips of musical ideas and export MIDI files which you can import in Ableton Live, Reason, GarageBand or any music creation software that accepts MIDI files.

Install

npm install scribbletune

Use it to create a MIDI clip by running a JS file from your terminal using node.js

const scribble = require('scribbletune');
const clip = scribble.clip({
    notes: scribble.scale('C4 major'),
    pattern: 'x'.repeat(7) + '_'
});

scribble.midi(clip, 'c-major.mid');

You can use Scribbletune even in the browser with Tone.js!. There are a couple of ways to do this. A quick and dirty way is to make sure to pull in Tone.js followed by the latest browser version of Scribbletune.

<script src="https://cdnjs.cloudflare.com/ajax/libs/tone/<LATEST-VERSION-FROM-CDNJS>/Tone.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/scribbletune/<LATEST-VERSION-FROM-CDNJS>/scribbletune.js"></script>

This will expose a global object called scribble which you can directly use to run the methods from Scribbletune in conjunction with Tone.js

The recommended way for the browser, however, is to import it like this

const scribble = require('scribbletune/browser');

This will provide the same API but augment it a bit to support browser based functionality.

Similarly, you can use the Scribbletune API for Max for Live development by doing

const scribble = require('scribbletune/max');

Just like the browser version this too will enable the same API but with some added bells and whistles for Max for Live.

Visit scribbletune.com for documentation, tutorials and examples! Listen to music generated with Scribbletune on Soundcloud.

scribbletune's People

Contributors

aimorris avatar andreaskaemmerle avatar brandongregoryscott avatar chrisantaki avatar deekshithshetty avatar dependabot[bot] avatar ericdimarzio avatar gabrielbarker avatar iva2k avatar jazz-soft avatar justinlevi avatar kant avatar kylir avatar mickmister avatar nfreear avatar nthngalone avatar palashmon avatar paneraallday avatar patrickshaughnessy avatar planetcohen avatar qchenevier avatar skateonrails avatar walmik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scribbletune's Issues

Create modes or scales with a single string arg

Currently a mode or a scale is created like this:
var cMajorScale = scribble.scale('c', 'major'); // ['c3', 'd3', 'e3', 'f3', 'g3', 'a3', 'b3', 'c4']

If you want it in a specific octave then,
var cMajorScale4 = scribble.scale('c', 'major', 4); // ['c4', 'd4', 'e4', 'f4', 'g4', 'a4', 'b4', 'c5']

Make a provision to create the scale with a single string argument, like
var cMajorScale = scribble.scale('c major'); // ['c3', 'd3', 'e3', 'f3', 'g3', 'a3', 'b3', 'c4']

or,
var cMajorScale4 = scribble.scale('c major 4'); // ['c4', 'd4', 'e4', 'f4', 'g4', 'a4', 'b4', 'c5']

Update pattern style in MIDI generation to mimic browser style pattern

1 bar is 512 ticks long
x or 4n is 128 ticks long (512/4)

with out any square brace, x is always is the value of subdiv, which is 4n by default, hence 128 ticks
once a square brace comes in to the picture, it sets a compound value which is used to compute the ticks based on the number of notes in the square brace

in [x], each x is 128/1 long
in [xx], each x is 128/2 long
in [xxx], each x is 128/3 long
in [xxxx], each x is 128/4 long
[xxxx]x is 128/4 and 128

[x[xx]] is 128/2 and 128/2 by 2
[x[xxx]] is 128/2 and 128/2 by 3
[x[xx]x] is 128/3 with the second one being 128/3 by 2

at the onset, without any square braces, the default subdiv length is 512/4=128
as soon as a square brace is opened, it should get divided by 4, in this case 128/4
when more squares are opened up, it gets further divided by 4
as squares close, it doubles back up

Rudimentary solution

Utils already has the necessary method to convert string pattern to array
For e.g. x[x[xx]x] becomes ['x', ['x', ['x', 'x'], 'x']]

var notesArr = [];

var subdivHdr = 128; // 4n
var defaultNoteLength = subdivHdr;

function r(arr, noteLength) {
  arr.forEach(function(el, idx) {
    if (typeof el === 'string') {
      notesArr.push(noteLength);
    }
    if (Array.isArray(el)) {
      r(el, noteLength/el.length)
    }
  });
}

Beats w/ Triplets?

Not an issue, more of a question.
Is it possible to create beats with triplets in them, can it be done, is it something being worked on?

Allow for note to be both lower and UPPERCASE

Probably not really an issue (I'm very very new to Git,Github) but...

scribble.clip() allows for notes to be written with lower case 'c4' and not 'C4'.
Is that by design ie. uppercase letters are for chords only?
Or would it be beneficial to allow both lower and upper in?
by modifying this:

	// Validate provided notes
	params.notes.forEach(el => {
		assert(el.match(/[abcdefg]#?[0-9]/g) !== null, el + ' is not a valid note!');
	});

To this:

	// Validate provided notes
	params.notes.forEach(el => {
		assert(el.match(/[a-gA-G]#?[0-9]/g) !== null, el + ' is not a valid note!');
	});

btw, I have worked on the simplistic UI for Scribbletune, find it here: https://github.com/highri5e/ElectroScribble

Default chords no longer work

In mode.js, the defaults (in particular the root) are set after checking the regex stuff on root. So just calling scribble.modes() scribble.mode() throws an error at line 16 because you assume there's always going to be a string in the first argument you can do a match on, but it looks like undefined should mean 'c'.

You also assert that the second argument must be a string that exists in modes before you assign a default.

c6 renders as c6 chord

While creating a clip, one can set up individual notes or chords in the notes param. For instance both of the following are valid clip creation methods:

var clip = scribble.clip({
  notes: ['c4', 'e4', 'g4']
});

Use chord names directly:

var clip = scribble.clip({
  notes: ['Cmaj', 'Am']
});

All this is good untill a sixth chord is confused for the sixth octave. For example setting c6 as the note returns the C Sixth chord instead of the C note on the 6th octave!

Importing error

Hi,
I did my coding for the scribble-tune. How to import it in the Ableton live 9 if i import it the music is not playing there is no sound.

Modes for d onward shud return next octave for notes before it

If a mode or scale from C is requested, then the current implementation works fine. But in case of D and onward, it should return next octave for notes before the root.

For example
Modes.get('D', 3, 'ionian') should return:
D3, E3, F#3, G3, A4, B4, C#4, D4

Currently it returns
D3, E3, F#3, G3, A3, B3, C#3, D4

Add half notes, quarter notes, etc...

Looking at the README, I could not find any references to setting notes to different lengths. Is there currently a way to do this, or does this feature need to be added in?

Create a custom chord

I would like to be able to create a chord by supplying an array of notes as a parameter. Is that possible with the current version?

If not, maybe something like the following? ...

var clip = scribble.clip({
    notes: [scribble.chord(['f2', 'c4', 'e4', 'g4']), scribble.chord(['c2', 'e4', 'g4', 'b4']), scribble.chord(['a2', 'c4', 'e4', 'g4'])],
    pattern: 'x_x_x_--'.repeat(8)
});

Allow passing an array of notes for a single note on event

Currently the notes array accepts individual notes

scribble.clip({
    notes: ['c3', 'd4', 'f4']
});

or chord names

scribble.clip({
    notes: ['Csus2', 'F#Maj', 'Am']
});

Allow passing arrays as well. So the notes array could be set up like this:

scribble.clip({
    notes: [ 
        [ 'c3', 'g3', 'd3' ],
        [ 'd3', 'a3', 'e3' ],
        [ 'e3', 'b3', 'f#3' ]
    ]
});

or for that matter in a mix mode,

scribble.clip({
    notes: [ 
        [ 'c3', 'g3', 'd3' ],
        'd5',
        'Emin'
    ]
});

the mode/scale method doesnt handle flattened accidentals

If we were to get the the Eb phrygian mode, they can only get it by using D#:

var scribble = require('scribbletune');
scribble.mode('D#', 'phrygian'); // returns [ 'd#4', 'e4', 'f#4', 'g#4', 'a#4', 'b4', 'c#5', 'd#5' ]

If we were to try the same with Eb instead, an incorrect output is obtained:

var scribble = require('scribbletune');
scribble.mode('Eb', 'phrygian'); // returns [ 'b5', 'eb5' ]

scribble.scale is case sensitive

Initially scribbletune denoted accidentals - the sharp (♯) and flat (♭) notes as sharps by default. Recently the functionality was added to make flats (♭) as the default way to denote accidentals with provision to still recognize them if sharps were passed to the methods. However scribble.scale also referenced as scribble.mode doesn't recognize this change unless the arguments are all lower case.

For instance scribble.mode('db', 'major') returns [ 'db4', 'eb4', 'f4', 'gb4', 'ab4', 'bb4', 'c5', 'db5' ] but scribble.mode('Db', 'major') returns [ 'b5', 'Db5' ] and scribble.mode('db', 'Major') just throws an error as it cannot recognize Major (it expects major)

Tests that correctly returns notes for scribble.mode('Db', 'major'); and scribble.mode('Db', 'Major'); are required to be added.

Add JSDoc style comments wherever missing

Currently there are some functions without sufficient comments (needs to be in JSDoc style). Also existing comments need to be verified with the functionality itself. This needs to be reflected in the documentation which is managed via gh-pages branch in this repo.

Underscored patterns

There needs to be a provision for the underscore as well so that a quarter note (x) can be extended to a half note (x_) or a whole note (x___) or a double note/breve (x_______) or bigger

What's the best way for playing midi in Bash / MacOS?

I use this code:

const scribble = require('scribbletune');
let notes =  ['c4','c4','e4','e4','g3','c5','c5','c5','e5','g3'];
let clip = scribble.clip({
	notes: scribble.transposeNote(notes, 3),
	pattern: 'x_xx_xx_x_x_x_xx'.repeat(4)
});

scribble.midi(clip, 'transpose.midi');

Then I try to use timidity (brew install timidity). I here the first note and then it just crashes. In bash it tools like this:

$ timidity transpose.midi
Check URL type=7
Check URL type=2
Check URL type=1
open url (type=1, name=/usr/local/Cellar/timidity/2.14.0/share/timidity/timidity.cfg)
url_file_open(/usr/local/Cellar/timidity/2.14.0/share/timidity/timidity.cfg)
mmap - success. size=4625
Check URL type=7
Check URL type=2
Check URL type=1
open url (type=1, name=~/.timidity.cfg)
url_file_open(~/.timidity.cfg)
Playing transpose.midi
MIDI file: transpose.midi
Check URL type=7
Check URL type=2
Check URL type=1
open url (type=1, name=transpose.midi)
url_file_open(transpose.midi)
mmap - success. size=346
Format: 0  Tracks: 1  Divisions: 128
Check URL type=7
Check URL type=2
Check URL type=1
open url (type=1, name=Tone_000/000_Acoustic_Grand_Piano.pat)
url_file_open(Tone_000/000_Acoustic_Grand_Piano.pat)
Check URL type=7
Check URL type=2
Check URL type=1
open url (type=1, name=/usr/local/Cellar/timidity/2.14.0/share/timidity/Tone_000/000_Acoustic_Grand_Piano.pat)
url_file_open(/usr/local/Cellar/timidity/2.14.0/share/timidity/Tone_000/000_Acoustic_Grand_Piano.pat)
mmap - success. size=1336363
Segmentation fault: 11

Add support for setting middle C

Currently Scribbletune defaults to C4. This is fine but technically we must provide a way to change this. For instance most software DAWs such as Ableton Live and Propellehead Reason have C3 as the middle C. So users (including me) of these softwares have to manually transpose what comes from Scribbletune an octave up. We should allow users to set the middle C when they require or import Scribbletune or at least set it up right after they import.

error running command node c.js

this is what terminal sad:

Pascals-MacBook-Pro:Neuer Ordner 9 surreal1212$ node c.js
module.js:549
throw err;
^

Error: Cannot find module './chord'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (/Users/surreal1212/scribbletune/src/index.js:3:15)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
Pascals-MacBook-Pro:Neuer Ordner 9 surreal1212$

Install process issues

Hi,
I installed Node.js and npm files. Now how to install scribble tune and how to run it from the terminal.
can anyone help me..

Corporate Image

Congratulations for this incredible tool!!

Maybe you wanna change something, so the crawlers don't get this image when we link your library (or maybe you don't)

captura

Thanks for your job!

E#sus2 TypeError: Cannot read property '1' of null

Hello i try to use scribbletune version 0.11.2

`
const scribble = require('scribbletune');

let chords = scribble.clip({
notes: ["E#sus2"],
pattern: 'x'
});

scribble.midi(chords, 'chords.mid');
`

`
jsmidgen/lib/jsmidgen.js:27
var note = matches[1].toLowerCase(), accidental = matches[2] || '', octave = parseInt(matches[3], 10);
^

TypeError: Cannot read property '1' of null
`

Breaking up beats in a pattern

I started writing a PR that would allow you to to put spaces in patterns for organization:

pattern: 'x_x_  x_x_  x_x_  xxxx'

The pattern would simply remove the spaces before processing the clip. However, I'm not entirely sure that is the best approach, as users may want to get the length of the pattern. This would lead to more work for the user to remember to filter out spaces. Instead, I wonder if a simple example of string concatenation in the docs would suffice. Something like this:

pattern: 'x_x_' + 'x_x_' + 'x_x_' + 'xxxx'

Any thoughts?

Feature: WebAudio Support

Hello :)
First of all, excellent library :D

Bringing this JS library to the browser stage will be really nice (browser live coding/jamming sessions anyone?). And since the WebAudio API has support for MIDI, it would be a good fit.

I could try implementing this and making a PR but just wanted opinions :)
Cheers!

Love this ! can we setup automation to import clips into Ableton.

First off, Loved this whole idea !
The kicker for me is how this could be used to easily create quite complex harmonies & beat patterns. Im going to try to expand on that soon. We could also use it to co-relate music theory to known number patterns / mathematical formulas or vice versa, use math formulas to construct music patterns.

Possibly even have a new kind of UI that allows you to visualize chord / harmony / beat patterns as editable mathematical charts. mind explodes

For the moment, I felt it'd be great if we could automate the process of importing the clips into ableton. Seems tedious, especially as the modifications grow.

we could have predefined channels as bass / drums / wtev in ableton. The automation simply matches filename to channel name and imports it in.

Possibly a max for live automaton OR scribble tunes directly exporting an ableton project ?
any thoughts ?

window is not defined error

Hi there; recently picked this up as I wanted to play about with some audio generation - so.

I assume from the error I am getting, this is made to run in the browser? As running it via node gives me the above error. Is there anything I can do for this?

Thank you in advance.

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.