Giter Site home page Giter Site logo

pitch's Introduction

Pitch

Manipulate note pitches with ease. Uses a two valued coordinated system to represent the pitch. Play nicely with intervalo

About

This is an idea of how teoria.js can be modularized to a very granular level. Inspired by a talk with @saebekassebil and the lodash library.

Usage

var pitch = require('pitch');
pitch('a4') // -> [0, 0];
pitch.str([0, 0]) // -> a4
pitch.name([0, 0]) // -> a

pitch.transpose('a2', [-1, 2]) // -> [-1, 2]

Also, you can require the individual methods you need:

var parse = require('pitch/parse');
var transpose = require('pitch/transpose');
var str = require('pitch/str');
str(transpose(parse('c2'), [-1, 2])) // -> d2

API

This is a list of the implemented methods. All of they are available by default if you require the entrie library:

var pitch = require('pitch');

You can load only the desired method:

var transpose = require('pitch/transpose');

pitch.accidental(coord)

Returns the string symbolic of the accidental sign (x, #, b or bb)

pitch.accidental(pitch('c#2')); // => '#'

pitch.key(coord)

Returns the piano key number

pitch.key(pitch('a4')); // => 49

pitch.letter(coord)

Returns the name of the note, in lowercase letter.

Note: this method is called name in teoria.js

pitch.letter(pitch('D#3')); // => 'd'

pitch.octave(coord)

Returns the numeric value of the octave of the note

pitch.octave(pitch('f#5')); // => 5

pitch.parse(str | coord)

Returns the coord of the given string (in scientific notation). If the param is an array of two elements, it returns the array

pitch.parse('f#2');     // => [ -4, 3 ]
pitch.parse([ -4, 3 ])  // => [ -4, 3 ]

Note: pitch('c#2') and pitch.parse('c#2') are equivalents.

pitch.str(coord)

Alias: pitch.toString(coord)

Returns a string representation of the given coordinates in scientific notation.

  pitch.str([ -4, 3 ]);        // => 'f#2'
  pitch.toString([ -4, 3 ]);   // => 'f#2'

pitch.transpose([pitch], interval)

Transpose the a pitch by an interval. Both parameters must be in coord notation. You can use intervalo library.

If only one interval param is supplied, returns a tranposer: a function that transposes certain interval.

For example, given a M2 ([ -1, 2]) interval:

  pitch.transpose(pitch('e3'), [-1, 2]);      // => [-3, 3] (f#3)
  var transposer = pitch.transpose([-1, 2]);  // Function
  transposer(pitch('e3'));                    // => [-3, 3]

Build dist file

Build a web ready distribution:

npm install
npm test
npm start

## License

MIT License

pitch's People

Contributors

danigb avatar saebekassebil avatar

Stargazers

Michael Anthony avatar

Watchers

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