[HN Gopher] Tonal.js: Functional music theory lib
       ___________________________________________________________________
        
       Tonal.js: Functional music theory lib
        
       Author : brianzelip
       Score  : 47 points
       Date   : 2024-04-02 10:35 UTC (1 days ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | jarmitage wrote:
       | Used in https://strudel.cc (TidalCycles' JavaScript version)
       | 
       | Specifically https://strudel.cc/learn/tonal/
        
       | hasty_pudding wrote:
       | "all functions are pure, there is no data mutation, and entities
       | are represented by data structures instead of objects."
       | 
       | God i love to see this
        
         | recursive wrote:
         | In javascript, what data structure can you implement without
         | objects? Pretty much nothing. Even arrays are objects.
        
           | metaxy2 wrote:
           | 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.
           | 
           | [1] https://github.com/tonaljs/tonal/blob/main/packages/chord
           | /in...
        
             | pcthrowaway wrote:
             | 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.
        
               | eitacaraleo wrote:
               | Uh... what? It's quite the opposite; why would you need a
               | class for linked lists and trees?
        
               | hasty_pudding wrote:
               | You definitely need generic node objects to define the
               | nodes.
               | 
               | You could have a completely stateless class/object that
               | would manipulate those nodes and add them and remove them
               | from the data structure.
        
           | hasty_pudding wrote:
           | 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.
           | 
           | Some further explanation about this:
           | 
           | https://www.goodreads.com/quotes/702062-immutable-objects-
           | ar...
           | 
           | a semi-nuanced discussion:
           | 
           | https://www.reddit.com/r/scala/comments/ejwsp1/is_mutability.
           | ..
           | 
           | you can just Google mutable state to find more info.
           | 
           | separating your data structures and functions in many cases
           | will make your code cleaner and more bug free.
        
       | smrtinsert wrote:
       | Wonderful. Wanted something like this forever. Glad it exists
        
       | duranduran wrote:
       | Tonal is great! I use it extensively here: https://app.bars.ai
       | 
       | 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.
        
       | unikeko wrote:
       | this initially confused me; you might not be aware, but
       | "functional" is a bit overloaded term with regard to music
       | theory, see: functional harmony
        
       | hannibalekta wrote:
       | Im working on a music learning app to study jazz licks and this
       | is exactly what I needed. Thanks!
        
       | grimmdude wrote:
       | I love Tonal.js, have used it for many personal projects
       | including https://github.com/grimmdude/MidiWriterJS
        
       ___________________________________________________________________
       (page generated 2024-04-03 23:00 UTC)