Coder Social home page Coder Social logo

punkt's Introduction

PunKt - Kotlin Punk

GitHub Workflow Status

A live coding music library/environment for Kotlin. For software developers who want to dive into live coding music.

"Punkt" is "point" in Polish.

Punkt demo

Demos:

Rationale

  • minimal - just a sequencer playing samples and synths designed in SuperCollider
  • easy to install - a library + template project, just git clone, run and enjoy
  • no custom IDE - could be started directly from IntelliJ IDEA or command line with any Kotlin-aware editor
  • data-oriented - patterns and melodies represented as data structure, making it easy to test and visualize

How to start

  1. Install SuperCollider (at least 3.10) and sc3-plugins
  2. Clone template project git clone https://github.com/pjagielski/punkt-template.git
  3. Start SuperCollider, boot server (Server->Boot Server) and run punkt-synths.scd (in case of "Memory allocation problems": clone punkt project and run src/main/resources/punkt.scd in SuperCollider.)
  4. Run Main.kt in punkt-template
  5. Profit! Just edit src/main/kotlin/live.kts in your favourite editor for live-coding

Why Kotlin?

  • statically typed, compiled - you get code completion and compile-time errors for free
  • sequence API - great standard library with lazy immutable sequences for making patterns
  • DSL builders - extension methods and operator overloading makes it easy to create powerful DSLs
  • scripting - a file watcher and API for compiling/evaluating script whenever it changes
  • coroutines - makes trivial to trigger an asynchronous event from anywhere in your code
  • mainstream - it's great to learn Clojure or Haskell, but it's even better that your project uses technology that reaches lots of potential users ;)

Minimal example

    patterns(beats = 8) {
        + repeat(1).sample("bd_haus")       
    }

Plays "bd_haus" sample every beat.

What happened here? punkt highly relies on durations to create patterns. If we want to play "bd_haus" sample every beat, we could specify this by a list of beats, like listOf(0, 1, 2, 3, ...). We could use rangeTo function (e.g. 0..7) to create a fixed range of beats. In punkt instead, you specify the durations between the beats, and a starting point - which defaults to 0 by this repeat function (which is not repeat from Kotlin standard library). This has some advantages:

  1. in simple cases, you repeat single value or cycle through small series of values
  2. this creates infinite sequence of beats, which is helpful if you don't know upfront how many beats you need ;) that's why we need to narrow the resulting collection to fixes number of beats with this patterns(beats = 8) {..} function.

Another example: 4 on the floor beat:

    patterns(beats = 8) {
        + repeat(1).sample("bd_haus") // every beat starting from 0
        + repeat(2).sample("claps", at = 1.0) // every even beat, starting from 1     
        + repeat(1).sample("hat_2", at = 0.5, amp = 0.5f) // every beat, starting from 0.5
    }

Evaluates to:

sample played at beats
"bd_haus" [0,1,2,3,4,5,6,7]
"claps" [1,3,5,7]
"hat_2" [0.5,1.5,2.5,3.5,4.5,5.5,6.5]

Melody phrases

punkt also uses similar technique to create melodies. But melodies, apart from time when the sound should play, require a note (pitch), which should play. To make it more musically correct, these notes should be part of some musical scale. That's why we start by creating a scale object using DSL from scale package:

    val scale = Scale(C.sharp(), minor)

The notes of C# minor are: C#,D#,E,F#,G#,A,B (https://en.wikipedia.org/wiki/C-sharp_minor)

Then we can use phrase function, which takes sequence of degrees of given scale and sequence of durations to create a melody:

    patterns(beats = 8) {
        + scale.low()
            .phrase(
                degrees(listOf(0,-4,-2,-1).flatMap { listOf(it,it,it) }),
                cycle(0.75, 0.75, 0.5))
            .synth("tr808", amp = 0.2f)
    }

This creates following notes:

beats note degree
0, 0.75, 1.5 C# 0
2, 2.75, 3.5 F# -4
4, 4.75, 5.5 A -2
6, 6.75, 7.5 B -1

Which is the "Shape of you" bassline ;)

More examples

TB-303 pentatonic arpeggio with LFO

    val pentatonic = Scale(C.sharp(), pentatonic)
    val lfo = LFO(1000, 3200, length = 1.5)
    
    patterns(beats = 8) {
        + pentatonic.low()
            .phrase(degrees(cycle(cycle((0..4)).take(10).toList())), cycle(0.25))
            .synth("tb303", amp = 0.2f)
            .params("sus" to 0.3, "dec" to 0.2, "start" to 100)
            .params("cutoff" to lfo)
    }

4-step chord progression with lead synth

    val scale = Scale(C.sharp(), minor)
    val progression = listOf(Chord.I, Chord.IV, Chord.VI, Chord.VII)

    patterns(beats = 8) {
        + scale
            .phrase(
                progression.flatMap { listOf(it, null, it) }.toDegrees(),
                cycle(1.0, 0.25, 0.75)
            )
            .synth("lead", amp = 0.25f)
            .params("cutoff" to 1500)
    }

Inspirations

  • ORCΛ - simplicity (just a sequencer)
  • openRNDR - kotlin script-driven live coding
  • Leipzig - music as data
  • FoxDot - synth design, OSC implementation
  • Tidal - patterns, SuperDirt
  • Sonic-Pi - live loops, script-driven live coding

Changelog

0.3.0 - 09.09.2020

  • introduced separate tracks with global effects
  • new global effects: reverb, delay, djf
  • new effects: djf, waveDist, squiz
  • new synths: piano, bass8
  • new note methods: amp, track
  • fluent API for effects

0.2.0 - 17.05.2020

  • introduced effects
  • new effects: lpf, hpf, delay, dist, chop
  • new synth: lead
  • BREAKING: synth params API cleanup
  • events logging

0.1.0 - 20.04.2020

  • initial version ;)
  • sample and loop support
  • new synths: tb303, tr808, plucklead, da-funk

Roadmap

  • OSC/MIDI out
  • OSC/MIDI in
  • add effects on separate channels (0.3.0)
  • pattern randomization
  • visualization

License

Copyright © 2020- Piotr Jagielski

Punkt is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

punkt's People

Contributors

pjagielski avatar syknapse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

punkt's Issues

SuperCollider memory allocation problems

Hey, the library looks great, thanks for creating this!

I tried to launch the sample from punkt - template, but it seems like SuperCollider buffers are not handling it well using default setup.
It plays for a second or two and then stops, and SuperCollider server is outputting

FAILURE /s_new alloc failed, increase server's memory allocation (e.g. via ServerOptions)

I tried to increase buffer size using ServerOptions, but it did not help much.
Can you share your setup on this?

SynthDef cannot be found on SuperCollider 3.11.0

I have followed the steps on the README file, but I receive an error on SuperCollider 3.11.0

  • Clone punkt and punkt_template
  • Open punk_template in IntelliJ.
  • Open SuperCollider 3.11.0, and open and run punkt.scd
  • Run main.kt on IntelliJ

In IntelliJ, the project seems to be running nicely:

In SuperCollider, the following lines are dropped:

FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef play1 not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef tb303 not found
FAILURE IN SERVER /s_new SynthDef not found

Can't get it started

Complete newb here:

I tried to install supercolider from the ppa on ubuntu 18.04. It installed SC 3.9.1, which might be outdated.

When running Main.kt it complained about not finding 2 syntdefs: play1 and tb303

Do I have to install 3.11 to have this running=

Live updating not working anymore?

I have cloned the repo yesterday. Everything works but the live update as I change the live.kts kotlin script is not triggering. Might be due to a Kotlin update, since the repo was last updated last year? I'd love if it worked again, hope it can be fixed

Not connecting well to SuperColider

Hey,

I followed the instruction, but after running the server, script, and then program in the template, I see as if they communicate with each other, but SD throws over and over again the following errors:

*** ERROR: SynthDef freeGroup not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef lead not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef dist not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef chop not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef djf not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef freeGroup not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef freeGroup not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef lead not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef dist not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef chop not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef djf not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef freeGroup not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef freeGroup not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef lead not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef dist not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef chop not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef djf not found
FAILURE IN SERVER /s_new SynthDef not found
*** ERROR: SynthDef freeGroup not found
FAILURE IN SERVER /s_new SynthDef not found
FAILURE IN SERVER /n_set Node 1101 not found
FAILURE IN SERVER /n_set Node 1102 not found
FAILURE IN SERVER /n_set Node 1103 not found
FAILURE IN SERVER /n_set Node 1104 not found
FAILURE IN SERVER /n_set Node 1106 not found
FAILURE IN SERVER /n_set Node 1107 not found
FAILURE IN SERVER /n_set Node 1108 not found
FAILURE IN SERVER /n_set Node 1109 not found
FAILURE IN SERVER /n_set Node 1111 not found
FAILURE IN SERVER /n_set Node 1112 not found
FAILURE IN SERVER /n_set Node 1113 not found
FAILURE IN SERVER /n_set Node 1114 not found
FAILURE IN SERVER /n_set Node 1116 not found
FAILURE IN SERVER /n_set Node 1117 not found
FAILURE IN SERVER /n_set Node 1118 not found
FAILURE IN SERVER /n_set Node 1119 not found
FAILURE IN SERVER /n_set Node 1121 not found
FAILURE IN SERVER /n_set Node 1122 not found
FAILURE IN SERVER /n_set Node 1123 not found
FAILURE IN SERVER /n_set Node 1124 not found

In the same time in IntelliJ it looks like it sends normally:

[DefaultDispatcher-worker-8] INFO pl.pjagielski.punkt.jam.Jam - beat 23.5, sample 909cp
[DefaultDispatcher-worker-6] INFO pl.pjagielski.punkt.jam.Jam - beat 23.5, synth lead, note 41, params [sus, 0.5, dec, 0.75, res, 0.1, cutoff, 1753.9036]
[DefaultDispatcher-worker-6] INFO pl.pjagielski.punkt.jam.Jam - beat 23.5, fx dist, params [drive, 0.41950902]
[DefaultDispatcher-worker-6] INFO pl.pjagielski.punkt.jam.Jam - beat 23.5, fx chop, params [sus, 0.6060606, chop, 1.0]
[DefaultDispatcher-worker-6] INFO pl.pjagielski.punkt.jam.Jam - beat 23.5, fx djf, params [cutoff, 0.35024077]
[DefaultDispatcher-worker-6] INFO pl.pjagielski.punkt.jam.Jam - beat 23.75, sample 909cp
[DefaultDispatcher-worker-8] INFO pl.pjagielski.punkt.jam.Jam - beat 23.75, synth lead, note 56, params [sus, 0.5, dec, 0.75, res, 0.1, cutoff, 1738.0347]
[DefaultDispatcher-worker-8] INFO pl.pjagielski.punkt.jam.Jam - beat 23.75, fx dist, params [drive, 0.40980172]
[DefaultDispatcher-worker-8] INFO pl.pjagielski.punkt.jam.Jam - beat 23.75, fx chop, params [sus, 0.6060606, chop, 2.0]
[DefaultDispatcher-worker-8] INFO pl.pjagielski.punkt.jam.Jam - beat 23.75, fx djf, params [cutoff, 0.35006022]
[DefaultDispatcher-worker-8] INFO pl.pjagielski.punkt.jam.Jam - beat 24.0, fx DELAY, params [level, 0.75, echo, 0.75, echotime, 4.0]
[DefaultDispatcher-worker-8] INFO pl.pjagielski.punkt.jam.Jam - beat 24.0, fx REVERB, params [level, 0.75, room, 0.8, mix, 0.5]
[DefaultDispatcher-worker-8] INFO pl.pjagielski.punkt.jam.Jam - beat 24.0, fx COMP, params [level, 0.65, dist, 0.8]
[DefaultDispatcher-worker-8] INFO pl.pjagielski.punkt.jam.Jam - beat 24.0, fx DELAY, params [level, 0.75, echo, 0.75, echotime, 8.0]
[DefaultDispatcher-worker-8] INFO pl.pjagielski.punkt.jam.Jam - beat 24.0, fx REVERB, params [level, 0.75, room, 2.0, mix, 0.8]
[DefaultDispatcher-worker-8] INFO pl.pjagielski.punkt.jam.Jam - beat 24.0, fx COMP, params [level, 0.65, dist, 0.7]

Any idea what might it be?

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.