Giter VIP home page Giter VIP logo

tonal.note's Introduction

tonal.note

Build Status Code Climate js-standard-style npm version license tonal

tonal.note is collection of functions to manipulate notes:

var note = require('tonal.note')
distance('C3', '3m') // => 'Eb3'

It's part of tonal

Features

  • Midi and frequencies: midi, freq, fromMidi
  • Note properties: pitchClass, setOctave
  • Enharmonics: enharmonics
  • Transposition and distances: transpose, distance

Install

Only via npm: npm i --save tonal.note

Usage

Notes in tonal are represented by strings, and by default it uses scientific notation with the form: letter[accidentals][octave]/[duration].

Pitch classes are note names without octave and duration. They are used a lot to describe pitch sets like scales.

The note function returns a scientific notation of the given string or null if not valid string. It can be used to check if some string is a note:

// get a note
note('c2') // => 'C2'
note('fx') // => 'F##'
note('blah') // => null
// filter notes
['e', 'f', 'g', 'h', 'i'].filter(note) // => ['e', 'f', 'g']

Note properties

There are several functions to get note properties or to modify them:

// get properties
note.octave('C#4') // => 4
note.pitchClass('Bb5/4') // => 'Bb'

// set properties
note.setOctave(3, 'Bb0') // => 'Bb3'

#### Midi and frequencies

You can transform to midi and frequencies:

note.midi('A4') // => 69
note.fromMidi(13) // => 'Bb0'
note.freq(null, 'A4') // => '440'

Enharmonics

The note.enharmonics function return the nearest enharmonics of a note:

note.enharmonics('C') // => ['B#', 'C', 'Dbb']

#### Note transposition

You can transpose notes with the note.transpose function. The order of the parameters doesn't matter:

transpose('C2', '4A') // => 'F#2'
transpose('4A', 'C2') // => 'F#2'

If you transpose pitch classes (note names without octaves), the returned value will be a pitch class:

tranpose('A', '3M') // => 'C#'
tranpose('A5', '3M') // => 'C#5'

Also, you can partially apply the function to get a transposer:

var major3th = transpose('3M')
major3th('D') // => 'F#'

Transposers allows to work with arrays seamlessly:

['C', 'D', 'E', 'F', 'G'].map(transpose('3M')) // => ['E', 'F#', 'G#', 'A', 'B']
['1P', '3m', '5P'].map(transpose('C')) // => ['C', 'Eb', 'G']

Note distances

The note.distance function get the interval between two notes:

note.distance('C2', 'D2') // => '2M'

More...

Read the generated documentation or take a look at tonal

License

MIT License

tonal.note's People

Contributors

danigb avatar

Stargazers

zy0n.bear avatar

Watchers

 avatar James Cloos avatar  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.