Git Product home page Git Product logo

chord-transposer's Introduction

Chord Transposer

Javascript/TypeScript library for transposing musical chords within arbitrary text.

Usage

Install via npm:

npm install chord-transposer

Import the package using your preferred import syntax:

const Transposer = require('chord-transposer');

import * as Transposer from 'chord-transposer';

import { transpose } from 'chord-transposer';

Transposing

To a certain key signature:

> Transposer.transpose('F  C7 Bb   \nHello world').fromKey('F').toKey('D').toString()
'D  A7 G   \nHello world'

> Transposer.transpose('Fm  C Ab   \nHello world').fromKey('Fm').toKey('Dm').toString()
'Dm  A F   \nHello world'

up or down any number of semitones:

// Up 7 semitones.
> Transposer.transpose('F  Am Bb   \nHello world').fromKey('F').up(7).toString()
'C  Em F   \nHello world'

// Down 4 semitones.
> Transposer.transpose('F  Am Bb   \nHello world').fromKey('F').down(4).toString()
'Db  Fm Gb   \nHello world'

Auto Key Signature

If the key signature is not specified, the key will be inferred from the first chord.

> Transposer.transpose('F  C7 Bb   \nHello world').toKey('D').toString()
'D  A7 G   \nHello world'

> Transposer.transpose('Fm  C Ab   \nHello world').toKey('Dm').toString()
'Dm  A F   \nHello world'

> Transposer.transpose('F  Am Bb   \nHello world').up(7)
'C  Em F   \nHello world'

Supported Chords

> Transposer.transpose('C Cmaj CM Cm/F C7/F Csus4').toKey('F').toString()
'F Fmaj FM Fm/Bb F7/Bb Fsus4'

> Transposer.transpose('Cm Cmin C- Cdim Caug C+ C+5').toKey('Dm').toString()
'Dm Dmin D- Ddim Daug D+ D+5'

Parsing

When text is passed into transpose, it is parsed into an Array<Array<string|Chord>>. You can access these through tokens to parse however you like:

> Transposer
    .transpose('C  G  Am  G7/B  C    F  C   F   G7\nO Canada  Our home and native land')
    .tokens
[ [ Chord { root: 'C', suffix: '', bass: undefined },
    '  ',
    Chord { root: 'G', suffix: '', bass: undefined },
    '  ',
    Chord { root: 'A', suffix: 'm', bass: undefined },
    '  ',
    Chord { root: 'G', suffix: '7', bass: 'B' },
    '  ',
    Chord { root: 'C', suffix: '', bass: undefined },
    '    ',
    Chord { root: 'F', suffix: '', bass: undefined },
    '  ',
    Chord { root: 'C', suffix: '', bass: undefined },
    '   ',
    Chord { root: 'F', suffix: '', bass: undefined },
    '   ',
    Chord { root: 'G', suffix: '7', bass: undefined } ],
  [ 'O Canada  Our home and native land' ] ]

Key Signatures

You can see the current key signature of the text through getKey().

> Transposer.transpose('C  G').getKey()
KeySignature {
  _description: 'C',
  _ordinal: 0,
  majorKey: 'C',
  relativeMinor: 'Am',
  keyType: 1,
  rank: 0,
  _propName: 'C' }

> Transposer.transpose('C  G').up(4).getKey()
KeySignature {
  _description: 'E',
  _ordinal: 4,
  majorKey: 'E',
  relativeMinor: 'C#m',
  keyType: 1,
  rank: 4,
  _propName: 'E' }

chord-transposer's People

Contributors

ddycai avatar frigidrain avatar phjardas avatar dependabot[bot] avatar pcmnac 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.