Giter VIP home page Giter VIP logo

chuckdesigner's Introduction

ChucKDesigner

TouchDesigner => ChucK => TouchDesigner;

ChucKDesigner is an integration of the ChucK music/audio programming language with the TouchDesigner visual programming language. With ChucKDesigner,

  • TouchDesigner can run ChucK code at any sample rate, with any number of input and output channels.
  • TouchDesigner can receive and post-process ChucK's output such as audio or melodic information.
  • TouchDesigner can set ChucK global variables with TouchDesigner UI, CHOP streams, and Python scripting.
  • TouchDesigner can use Python callbacks to respond to changes in ChucK global variables.

ChucKDesigner consists of two custom operators, the ChucK Audio CHOP and the ChucK Listener CHOP. The ChucK Audio CHOP "runs" the ChucK code. TouchDesigner can also tell it how to update global variables. The Listener CHOP "listens" to a ChucK Audio CHOP. It can continuously stream out global floats and integers as ordinary CHOP data. Using a Python-based callback DAT, it can also access many more global variable types such as arrays, strings, and events.

Please use the issues and discussions pages on GitHub. You can also participate in the #ChucKDesigner channel in the ChucK Discord server.

Tutorials

Part 1 (Introduction):

Demo Video Screenshot

Part 2 (Python API):

Make a Drum Sequencer with ChucK in TouchDesigner

Installation

ChucK

ChucKDesigner is currently being built for ChucK 1.5.2.3 for TouchDesigner with 3.11 (2023 builds) and Python 3.9 (2022 builds). If you need to support something else, please check out earlier releases or commits of this repository.

Downloading ChucK is optional but highly encouraged! Use miniAudicle and the examples that come with the installation to learn ChucK. More educational resources are available from the ChucK homepage. ChucKDesigner is very similar to Chunity (the integration of ChucK with Unity), so you are also encouraged to learn about Chunity!

Windows

Download and unzip the latest Windows release. Copy the latest .dll files to this project's Plugins folder or %USERPROFILE%/Documents/Derivative/Plugins. That's all!

Building on Windows (Optional)
Clone this repository with git. Then update all submodules in the root of the repository with git submodule update --init --recursive.
Install Python 3.11 to C:/Python311/ and confirm it's in your system PATH.
Install CMake and confirm that it's installed by running cmake --version in a command prompt.
Then in this repository,
cmake . -DCMAKE_BUILD_TYPE=Release -Bbuild -DPYTHONVER="3.11"
Finally, open build/ChucKDesignerCHOP.sln and compile.

MacOS

Download and unzip the latest macOS release. Copy the latest .plugin and .dylib files to this project's Plugins folder or ~/Library/Application Support/Derivative/TouchDesigner099/Plugins. That's all!

If you'd like to build the ChucKDesigner plugins yourself, these are the instructions:

  1. Clone this repository with git. Then update all submodules in the root of the repository with git submodule update --init --recursive
  2. Install Xcode.
  3. Install CMake and confirm that it's installed by running cmake --version in Terminal. You may need to run export PATH="/Applications/CMake.app/Contents/bin":"$PATH"
  4. In a Terminal Window, export a variable to the TouchDesigner.app to which you'd like to support. For example: export TOUCHDESIGNER_APP=/Applications/TouchDesigner.app, assuming this version is a 2023 build or higher.
  5. Optional: depending on the Python version associated with the TouchDesigner you intend to use, run export PYTHONVER=3.11 or export PYTHONVER=3.9.
  6. In the same Terminal window, navigate to the root of this repository and run sh build_macos.sh
  7. Open ChucKDesigner.toe and play around!

API

Python interface to ChucK Audio CHOP

The ChucK Audio CHOP's functions:

  • .set_float(name: str, val: float)
  • .set_int(name: str, val: int)
  • .set_string(name: str, val: int)
  • .set_float_array(name: str, vals: List[float]) not numpy arrays!
  • .set_int_array(name: str, vals: List[int]) not numpy arrays!
  • .set_float_array_value(name: str, index: int, val: float)
  • .set_int_array_value(name: str, index: int, val: int)
  • .set_associative_float_array_value(name: str, key: str, val: float)
  • .set_associative_int_array_value(name: str, key: str, val: int)
  • .broadcast_event(name: str)
  • .set_log_level(level: int) 0 is None and 10 is "Crazy"

Suppose the ChucK Audio CHOP has compiled this code:

440. => global float freq;

SinOsc s => dac;

while(true) {
    freq => s.freq;
    10::ms => now;
}

This can be seen in the following image:

Float Example TouchDesigner Screenshot

In TouchDesigner, we can execute the Python code op('chuckaudio1').set_float("freq", 880.) This will set the global float variable named freq to 880. The code has been written to update the sine oscillator's frequency every 10 milliseconds, so you will immediately hear a change in the frequency. Note that the code below would not have led to a change in sound.

SinOsc s => dac;

440. => global float freq => s.freq;

while(true) {
    10::ms => now;
}

The reason is that global variables are not Unit Generators. Although freq has been chucked to s.freq, we still need code in the while(true) loop to update the oscillator's frequency.

Streaming global floats and integers in ChucK Listener CHOP

The ChucK Listener has a custom parameter for the ChucK Audio CHOP to which it should listen. Suppose we had used a ChucK Audio CHOP to compile this:

440. => global float freq;
0 => global int randInt;

SinOsc s => dac;

while(true) {
    freq => s.freq;
    Std.rand2(0, 10) => randInt;
    10::ms => now;
}

On the ChucK Audio Listener, there is a custom parameter for "Float Variables". In this field you can type any number of global variables, each separated by a single space. In this example, there's just one global float, so you can type freq. Similarly, in the "Int Variables" custom parameter, you can type randInt. The ChucK Listener will then output as ordinary CHOP information a single-sample with one channel named freq and another channel named randInt. The ordinary CHOP output of the Listener CHOP is only for global floats and global integers. However, all variable types can be received as Python callbacks, as explained in the next section.

Python Callbacks in ChucK Listener CHOP

In the example above, we used a global float freq and a global int randInt. Find the Float Variables and Int Variables custom parameters on the ChucK Listener CHOP and set them to freq and randInt respectively. Now freq will appear in the getFloat callback, and randInt will appear in the getInt callback.

# This is an example callbacks DAT for a ChucK Listener operator.
# In all callback methods, "listener" is the ChucK Listener operator.

def getFloat(listener, name, val):
    print(f'getFloat(name="{name}", val={val})')

def getInt(listener, name, val):
    print(f'getInt(name="{name}", val={val})')

def getString(listener, name, val):
    print(f'getString(name="{name}", val={val})')

def getEvent(listener, name):
    print(f'getEvent(name="{name}")')

def getFloatArray(listener, name, vals):
    print(f'getFloatArray(name="{name}", vals={vals})')

def getIntArray(listener, name, vals):
    print(f'getIntArray(name="{name}", vals={vals})')

Most of these callbacks are straightforward to understand, but the Event type syntax is worth discussing. Let this be the compiled ChucK code:

global Event pulse;
global Event notifier;

fun void playImpact() {
    SndBuf buf => dac;
    "special:dope" => buf.read;

    // chuck enough time so that the buf plays
    1::second => now; 
    
    // invoke getEvent("notifier") in TouchDesigner
    notifier.broadcast();
}

while( true ) {
    pulse => now;
    spork ~ playImpact();
}

At the beginning, there will be 2 channels of silent output by default. The line pulse => now; consumes time until we broadcast an event in TouchDesigner with Python:

op('chuckaudio1').broadcast_event('pulse')

The ChucK code will then spork a shred of playImpact(), which will play a short sound. After 1 second of playing the sound, ChucK will broadcast an event named notifier back to TouchDesigner. This event will show up in the getEvent() callback method, if notifier is in the ChucK Listener's custom parameter "Event Variables".

Chugins

ChucKDesigner supports Chugins, which are custom pre-compiled ChucK "plugins". The chugin should be located in a subfolder named "Chugins" of the "working directory" custom parameter on the ChucK Audio CHOP. For example, if the working directory parameter is assets, then the chugins should be in assets/Chugins.

chuckdesigner's People

Contributors

dbraun 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

Watchers

 avatar  avatar  avatar  avatar  avatar

chuckdesigner's Issues

Use the Text COMP as a code editor

The latest official builds of TouchDesigner introducted the Text COMP. This could be used as a fully featured code editor inside TouchDesigner. The default ChucKDesigner project should demonstrate a better looking live coding environment, a bit like miniAudicle.

Buffer has remnants after resetting

If I add a shred, reset, and then add a different shred, the CHOP still outputs about one frame of the first shred which should have been fully removed.

Should link against TouchDesigner's libpython when compiling

I think this is only a macOS issue. Right now I'm requiring a separate installation of Python 3.9. Instead, the CMake process should just find TouchDesigner's libpython.dylib. Note that this will be difficult to do in GitHub Actions because TouchDesigner would need to be installed. Maybe it can be installed headless but without creating a license.

Me again - Build issue

Im running into an issue building chucKDesigner on Mac. I've gone through all the steps but im running into an issue building it as I keep getting this error in my terminal:

The following build commands failed:
CodeSign /Users/me/Desktop/ChucKDesigner/build/Release/ChucKDesignerCHOP.plugin (in target 'ChucKDesignerCHOP' from project 'ChucKDesignerCHOP')
CodeSign /Users/me/Desktop/ChucKDesigner/build/Release/ChucKListenerCHOP.plugin (in target 'ChucKListenerCHOP' from project 'ChucKDesignerCHOP')
(2 failures)
All Done!

I'm not sure what I'm doing wrong but I've tried troubleshooting but I cant seem to figure it oue. Would greatly appreciate if anyone knew what I was doing wrong/ how to fix this! Thanks!

Newbie experience

Hello. Iam new in this world of Chuckdesigner, i am trying to learn. I am really good at Chuck, but I have not been able to run Chuckdesigner. My project just has one object and i am trying to add code on it. When i click on add code, or any other from the menu. it immediately crashes TD. See below images
ChuckObject
Chuck error

Difficulties running on Windows (Release ZIP issues, build issues)

Hi!

Saw this on the TouchDesigner InSession 18.0 from 2022-02-04 and figured I'd give it a shot, but I'm running into two issues on Windows:

  1. The directions in the README say to unzip the latest release and copy some dlls. Unfortunately, I'm unable to unzip the zip files for any of the releases using either the built-in zip capabilities in the file explorer in Windows 11, WinZip, or unzip in WSL2. All of them fail with pretty generic messages.
  2. I can't figure out how to build from source on Windows. If I run cmake from the root, I get an error about not being able to find chuck.yy.c. Figuring that I might need to compile a lex file, I ran flex on chuck.lex and copied the output to chuck.yy.c, which got me past that error (albeit with no guarantee that I did the right thing there) and yielded a cmake_install.cmake file. I tried running cmake -P cmake_install.cmake at that point and got:
[  1%] Building CXX object CMakeFiles/ChucKDesignerShared.dir/thirdparty/chuck/src/core/chuck.cpp.o
(include stack omitted here)
fatal error: AvailabilityMacros.h: No such file or directory
  715 | #include <AvailabilityMacros.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~

I admit that I'm still pretty poorly versed in make, and that I might be able to get past this point if I were better with it. I'll continue to work on getting past this, but both a working zip and some build instructions would be helpful here; happy to assist in any way that I can toward that end!

Thanks for this project and for all that you do for the TD community. 🙏

Again Me

Hi there mr Braun, sorry to ask again, but i connect the Chuck Listener creating the global variables as you explained. but it seems not to work(probably i am not connecting something) but i ask for our help again. The variable counter shows up in the Chuck listener but is always = 0, i dont know how to increase it as it is supposed to be increasing according to the code

ChuckListener
Code

Plugin Not loading

Hi. I just downloaded ChucKDesigner and wanted to fiddle around with it a bit however I have an issue in Chuck Audio where it says it failed to load the plugin. How do I fix this?
cerror
cerror

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.