Code Monkey home page Code Monkey logo

wayang's Introduction

Wayang

A Java library for displaying images on the Ableton Push 2 instrument. The project name, which refers to Javanese shadow puppet artistry, was chosen because it ties together the concepts Java, Push, and images.

Wayang photo

License

Dependencies

Wayang uses usb4java to communicate with the Push. For that to work, you need to have libusb installed on your system. If you are on Linux it is likely already installed, or you can follow their installation instructions. On the Mac, I recommend using Homebrew for all such needs; once it’s installed, you can simply run brew install libusb.

If you are already using the Open Lighting Architecture, perhaps through Afterglow, then libusb was installed as part of installing OLA.

Installing

Wayang is available through Maven Central, so to use it in your Maven project, all you need is to include the appropriate dependency.

Maven Central

Click the maven central badge above to view the repository entry for Wayang. The proper format for including the latest release as a dependency in a variety of tools, including Leiningen if you are using Wayang from Clojure, can be found in the Dependency Information section.

If you want to manually install Wayang, you can download the library from the releases page and put it on your project’s class path. Be sure you get the right version: the much larger file whose name ends -jar-with-dependencies.jar contains everything you need to communicate with libusb from Java. The smaller Wayang jar is for use with dependency management systems like Maven. You can download that one if you’d like, but you will then also be responsible for installing usb4java and any transitive dependencies it might have.

Usage

Once you have the Wayang library added as a dependency, all you need to do to draw to the Push display is:

import org.deepsymmetry.Wayang;

// ...

        BufferedImage displayImage = Wayang.open();
        Graphics2D graphics = displayImage.createGraphics();

// Perform whatever Java2D drawing operations you'd like to using the graphics object,
// then, whenever you want to update what is showing on the Push:

        Wayang.sendFrame();

// If you want to maximize your frame rate, you can also send frames asynchronously:

        Wayang.sendFrameAsync();

// If you are done talking to it, you can close, as below. Otherwise, the library cleans
// up for you when the JVM exits.

        Wayang.close();

The image you get from Wayang.open() is 960 pixels wide and 160 pixels tall, the same as the physical display. These values are also available as the constants Wayang.DISPLAY_WIDTH and Wayang.DISPLAY_HEIGHT.

This photo shows the results of running mvn test in the project directory:

Test display

Capturing Your Interface

You can save animated GIF files to provide highly meaningful documentation for your user interfaces, thanks to an embedded version of Elliot Kroo’s GifSequenceWriter. To do that, just call:

import org.deepsymmetry.GifSequenceWriter;

// ...

    ImageOutputStream output =
      new FileImageOutputStream(new File("out.gif"));

    // Pass in the displayImage buffer that Wayang.open() gave you, the
    // interval in milliseconds at which you update the display, and
    // whether you want the animation to loop:
    GifSequenceWriter writer =
      new GifSequenceWriter(output, displayImage, 50, true);

// Then whenever you are calling Wayang.SendFrame(), also call:

        writer.writeToSequence(displayImage);

// When you are done recording, call:

        writer.close();
        output.close();

Here is an example recording from Afterglow’s Push 2 interface:

Test display

Push Interface Documentation

Ableton has released the documentation that enabled the creation of this library as its own project on Github, push-interface.

Credits

Wyang photo by Gunawan Kartapranata, used under the Creative Commons Attribution-Share Alike 3.0 Unported license.

GifSequenceWriter by Elliot Kroo, used under the Creative Commons Attribution 3.0 Unported License.

License

Deep Symmetry

Copyright © 2016–2022 Deep Symmetry, LLC

Distributed under the Eclipse Public License 2.0. By using this software in any fashion, you are agreeing to be bound by the terms of this license. You must not remove this notice, or any other, from this software. A copy of the license can be found in LICENSE.md within this project.

wayang's People

Contributors

brunchboy avatar cansik 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

Watchers

 avatar  avatar  avatar  avatar  avatar

wayang's Issues

Speedup of sendFrame method

I am currently using your code for connecting to the push. But the frame rate is not that high (about 20 FPS). I think there are some speedup tweaks todo:

First of all, is there a reason why to just send 8 lines per transfer? Because the synchronous transfer is very time consuming. I just set the lines per transfer to 160 so we only have to send out the header and the data. Event he Ableton Push documentation does mention it:

"... the pixel data is typically sent using larger buffers, for example of 16kbytes each." (doc)

This fix brought up the frame rate to 27-28 FPS.

Second, it would be nice to have an asynchronous way to send the data. This could be done by replacing the existing submit method with following:

Transfer transfer = LibUsb.allocTransfer();
LibUsb.fillBulkTransfer(transfer, pushHandle, (byte) 0x01, headerBuffer, LibUsb::freeTransfer, null, 1000);

int result = LibUsb.submitTransfer(transfer);
if (result != LibUsb.SUCCESS) {
    throw new LibUsbException("Transfer of frame header to Push 2 display failed", result);
}

I'm currently working on this but it is not yet finished so I don't have an FPS speed up.

Third, is there a reason why to send the header and the data as two buffers? Wouldn't it be better to send them all together as one big chunk? The documentation tells us to send two messages, but I'm not sure if it makes any difference for the device. Do you know something about this?

And thank you for developing this library, I was first doing it myself but then stumbled over your repo ;)

Problems with libusb in Windows

I tried doing some testing based on a report from an Ableton engineer, and it appears there are complications setting up libusb access to the display in Windows. Since I have no physical Windows hardware and am not a Windows developer, I am requesting help and Pull Requests documenting the steps people need to take to get this working under Windows.

It seems likely related to a FAQ in the libusb project.

Create a Processing library?

It looks like it might be fairly straightforward to create a Processing library that lets people draw to the Push screen, as long as I can figure out a way to have access to usb4java without exporting all of that mess into the Processing environment. There are hints of that in the above-linked documentation, but it is not spelled out as clearly as I would like. Starting from the Eclipse template is probably easiest, even though that would require using Eclipse…

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.