npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

counterpoint

v0.1.0

Published

Generate interesting and well balanced species counterpoint (music!)

Downloads

11

Readme

Interactively generate interesting and well-balanced counterpoint following the strict rules of species counterpoint. See a live example here.

What is Species Counterpoint?

Species counterpoint is a time-honored method for learning how to write two or more lines of music that work well together. Infamous for its many rules, species counterpoint applies restrictions on both the horizontal and vertical dimensions of music — meaning that each line must be balanced and harmonious not only by itself left to right, but also up and down between all the lines at any given moment. The result is a kind of musical sudoku puzzle in which every decision resonates out in multiple directions.

Goals

The module is in development, and currently only supports creating a cantus firmus -- the horizontal dimension of counterpoint. Soon it will support 2-part first species counterpoint, and eventually all species.

Example

In this example we will build this cantus firmus in G major:

   [ 'G4', 'E5', 'D5', 'F#5','G5', 'B4', 'C5', 'A4', 'G4' ]
G5                            o
F#5                     o
E5          o
D5                o
C5                                        o
B4                                  o
A4                                              o
G4    o                                               o

      Do    La    Sol   Ti    Do    Mi    Fa    Re    Do
      1     6     5     7     1     3     4     2     1

Install the npm module.

npm install counterpoint

To generate a cantus firmus in G major:

var CantusFirmus = require('counterpoint').CantusFirmus

var cantus = new CantusFirmus('G major')

See the next note choices. At the beginning we have to start with G, but after that it gets more interesting.

cantus.choices()    => ['G']
cantus.addNote('G4')

cantus.choices()    => [ 'A4', 'B4', 'C5', 'D5', 'E5', 'G5',
                         'F#4', 'E4', 'G3', 'B3', 'C4', 'D4' ]

cantus.addNote('E5')
cantus.choices()    => [ 'D5', 'C5' ]  // choices are limited after a leap

cantus.addNote('D5')
cantus.choices()    => [ 'E5', 'F#5', 'G5', 'A5', 'B5',
                         'C5', 'B4', 'G4', 'A4' ]
cantus.addNote('F#5')

See what you've built so far:

cantus.cf()         => [ 'G4', 'E5', 'D5', 'F#5' ]

The choices are filtered for standard cantus firmus rules: no choices are given that would extend the range beyond a 10th, augmented and diminished intervals are avoided, dissonant melodic outlines are avoided, and more.


cantus.choices()    => [ 'G5', 'E5', 'F#4', 'A4', 'B4' ]

cantus.addNote('G5')
cantus.choices()    => [ 'A5', 'B5', 'F#5', 'E5', 'G4', 'B4', 'C5', 'D5' ]

cantus.addNote('B4')

You can also look ahead more than one note by giving cantus.choices() a number indicating the depth to search. If given a depth, choices returns an array of nDeep TreeNodes each with a val pointing to a pitch and next pointing to an array of more TreeNodes.

cantus.choices()     => [ 'C5', 'D5' ]
cantus.choices(2)    =>
[
  {
    val: 'C5',
    next: [
      { val: 'D5',  next: [] },
      { val: 'E5',  next: [] },
      { val: 'G5',  next: [] },
      { val: 'B4',  next: [] },
      { val: 'A4',  next: [] },  // I will pick this path -> C5, A4
      { val: 'E4',  next: [] },
      { val: 'G4',  next: [] }
    ]
  },
  {
    val: 'D5',
    next: [
      { val: 'E5',  next: [] },
      { val: 'C5',  next: [] },
      { val: 'F#4', next: [] },
      { val: 'G4',  next: [] },
      { val: 'A4',  next: [] }
    ]
  }
]

cantus.addNote('C5')
cantus.addNote('A4')

cantus.choices()     => [ 'B4', 'D5', 'E5', 'F#5', 'A5', 'G4' ]
cantus.addNote('G4')

We have worked our way back to the starting tonic and can now check if this is a valid cantus firmus. It will be checked to make sure there is a unique climax note (G5 in our case) along with other standard checks.

cantus.isValid()    => true
cantus.cf()         =>
   [ 'G4', 'E5', 'D5', 'F#5','G5', 'B4', 'C5', 'A4', 'G4' ]

Docs

View the api documentation here.

Development

Clone the git repository and install development dependencies:

git clone https://github.com/jrleszcz/computational-counterpoint.git
cd computational-counterpoint
npm install

To run eslint and tape tests:

npm test

To generate api documentation for api.md:

npm run docs