For people who are not aware, "functional harmony" means the extended system of tonal harmony that you hear in basically almost all music apart from a very few exceptions (eg free atonality, serialism etc but there aren't many compared to the very large amount of functional harmony out there).
It's "functional" because the chords in the harmony have the function of establishing key centres, moving towards and away from them, establishing transitions to remote key areas etc.
One of the best technical books about functional harmony is "Structural Functions of Harmony" by Arnold Schoenberg[1], which is much shorter than his "Harmonielehre" but really packed with interesting detail about key and chord relationships.
True. Almost all non-western music also has functional harmony though. The notable exceptions are things like Indian classical music and things like gamelan (which have static modal harmony).
@tonaljs/key gives you some specifically functional info, but the vast bulk of it as useful for non-functional analysis – though it does assume 12-tone equal temperament.
This is really nice! I am writing a guitar neck explorer tool to learn the patterns on the guitar neck. As I progress, I need to implement a lot more music theory than I really want to, so I was already looking around for something to integrate. This library will come in very handy. Nice work!
There are a few small areas where the library hiccups, like with bigger chords. I've been able to work around some of those things by reframing the chord as an inversion of N relative to the root of whatever scale I'm in. I haven't bothered to debug why it does that, but my little work around has been sufficient.
Unsolicited feedback because I clicked:
- Don't require picking a composition name before getting started
- Whatever scroll settings you have broke swipe to go back, and then when I tapped the back button I got stuck in an infinite loop between the home page and the create composition page
(shameless plug) If you're interested in something more focused on creating music with tools for generating melodies, chord progressions, drum beats, etc., check out PLAYA at https://github.com/ricardomatias/playa
Thanks for posting this! I've been experimenting with adding generative ambient music to my white noise app Ambiphone [0] using tone.js, but I've just been using manually written progressions and motifs, so I'm really excited to try this out.
Just a heads up that your example at https://observablehq.com/@ricardomatias/playa doesn't seem to be working at the moment because of browser autoplay restrictions - the console errors that look relevant are:
> An AudioContext was prevented from starting automatically. It must be created or resumed after a user gesture on the page.
> The AudioContext is "suspended". Invoke Tone.start() from a user action to start the audio.
Thanks for the heads up about the observable notebook. I suggest also having a look at the test cases, there's plenty examples in there on how to use the library.
Congratz on Ambiphone, I'm using it right now, it's a nice concept of creating your own ambient mix!
I am currently working on an app with React Native that helps users play along to songs and one of the features needed was displaying the various scales/modes on the fretboard so I basically built a mini library of my own to construct the note arrays.
This will be a great example to see how the library has handled the same problem.
Since we're all sharing, I've been using this recently to replace Teoria in an old project of mine (a simple PWA for Duolingo-style sight reading and ear training practice, with MIDI support):
Thanks for this! I've recently been exploring how to write a SATB four part harmony for a given melody / bass line, this takes a decent chunk of the boilerplate out for me.
try highlight → scale degree colors
or highlight → chord formula and put "1 3 5 7" in the chord formula box... then play with the pedal checkboxes to see how you can play that chord vertically, or more stylistically by using the pedal slides
yes, it doesn't really matter at all for this kind of system
you can set it to zero, to negative one... possibly to the imaginary constant
because this library does not actually make any sound. it's (to me) an implementation of 12tet, the standard western scale system which includes a bunch of scales and approximates the rest 'well' enough
I don't mean to lose my 'temper' here, but I think gp is hoping Note.freq(), Note.fromFreq(), etc. aren't locked into A440 as the examples imply. While >99% of the library doesn't deal with this at all, it would be handy nonetheless. Unfortunately, it's currently hard coded:
I don't think it matters at this abstraction layer? You reason about intervals, scales, chords etc the same regardless of the tuning system. That only matters for sound production, which this doesn't do.
It definitely assumes you're on a 12-tone system so is really only useful within western european music theory. But that is usually what people mean when they say "music theory" anyway.
I'm not aware of any, but you could probably compile it to WebAssembly with Emscripten and use it that way, the library seems fairly simple for something like that.
They're using objects, including arrays [1], so I think they would have been more precise to say that they're using objects and arrays as simple data structures rather than using OO features like inheritance and mutation.
This is just semantics then. If you're implementing a linked list or a tree without a class (or at the very least a function that behaves like a class), it's going to be awkward and clumsy.
Data-structures beyond what the standard lib gives you (string and array) are the main reason the addition of classes to JS was so helpful.
Absolutely. The navigation behaviors will have to be in functions though. And from an application code developer's perspective, the connection between these objects and functions may not be obvious. If only there were some way to associate behavior with state.
The whole point of the top comment is that they appreciate how this library chose not to associate behavior with state, and instead organized things as functions and data structures.
With the latter approach, the user is not limited to the bahaviors that the library author wrote. The data (not state) can be used freely. Similarly, the functions are not tied to any particular state - the data can come from anywhere, as long as it has the right shape.
Well, in principle you could have the node objects be created with an object literal in an outside builder function, and the manipulation also be done by outside functions. That's how it's done in languages without OOP. The question is how far are you willing to go to avoid doing anything that looks like OOP.
What they mean is functions and data are separate, emulating a more functional paradigm and less mutable state.
The functions are kept pure and the data is kept pure.
As opposed to an object oriented programming style in which data and functions share the same object and create bug ridden state machines thats not as easy to reason about.
I'm well aware of the pros and cons of mutability. I object (hah!) to this novel new use of the word "object". The concept is well defined by the ECMAScript spec.
Your first link's first sentence's first two words are "Immutable objects". No problem there. It doesn't conflate objects with mutability.
I have ideas but I don't think I'm getting them through. Most of the problems functional proselytizers have with objects come from inheritance and mutability. Instance methods from classes don't seem to conflict with any of the functional tenets.
As for mutability, I think it's good sometimes. Dates should have been immutable, but Maps are a good fit for mutation. Immutable maps might make sense too sometimes.
But I find it difficult to communicate about any of this when fundamental terminology is used in novel ways.
C# allows you to implement some data structures using `struct`s instead of `object`s. Probably not binary tree though.
I honestly still don't understand what you're getting at.
> a data structure in that context is clearly an ordered grouping of objects versus an unordered/loose grouping of objects.
What's an "ordered grouping"? What does "loose" mean? These are not gotchas. I'm trying my best here.
For me, if I were implementing a data structure, I would probably use objects. In fact, I'd probably use a class. I'm not trying to argue that data structures shouldn't be implemented in terms of objects or anything. My point is just that the tonal.js description is kind of nonsensical. Or at least hard to understand.
It's mostly a question of what the language considers to be an object.
There's often a stack-/heap-allocated dichotomy. Some languages consider stack-allocated structs not to be objects. They have no reference identity. Assignment has copy semantics. C# is one such language.
Specifically https://strudel.cc/learn/tonal/