Code Monkey home page Code Monkey logo

musictheory's Introduction

Music Theory

Build Status GoDoc

Explorations in music theory.

Usage

package main

import (
    mt "github.com/brettbuddin/musictheory"
    "github.com/brettbuddin/musictheory/intervals"
)

func main() {
    root := mt.NewPitch(mt.C, mt.Natural, 4)

    root.Name(mt.AscNames) // C4
    root.Freq()            // 261.625565 (Hz)
    root.MIDI()            // 72

    P5 := mt.Perfect(5)   // Perfect 5th
    A4 := mt.Augmented(4) // Augmented 4th

    root.Transpose(P5).Name(mt.AscNames)          // G4
    root.Transpose(A4).Name(mt.AscNames)          // F#4
    root.Transpose(P5.Negate()).Name(mt.AscNames) // F3

    mt.NewScale(root, intervals.Dorian, 1)
    // [C4, D4, Eb4, F4, G4, A4, Bb4]

    mt.NewScale(root, intervals.Mixolydian, 2)
    // [C4, D4, E4, F4, G4, A4, Bb4, C5, D5, E5, F5, G5, A5, Bb5]

    rootPosition := mt.NewChord(root, intervals.DiminishedSeventh)
    // [C4, Eb4, Gb4, A4]

    firstInversion := rootPosition.Invert(1)
    // [C5, Eb4, Gb4, A4]

    secondInversion := rootPosition.Invert(2)
    // [C5, Eb5, Gb4, A4]

    note := mt.NewNote(root, mt.D16) // C4 sixteenth note
    note.Time(mt.D4, 120)            // 125ms (quarter note getting the beat at 120 BPM)
}

ζ₯½γ—みます!

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.