Skip to main content

Rocket sync-tracker client

Project description

pypi travis

pyrocket

A rocket client written in Python.

editor

What is Rocket?

Rocket is a sync-tracker tool for synchronizing music and visuals in demoscene productions. It consists of an editor and a client that can either communicate with the editor over a network socket, or play back an exported data-set.

This project is only a client (for now), so you will have to find an editor. You include this client in your application so it can easily talk to an external editor or play back key frame data in the final product.

Do note that the rocket system can also be used for other purposes were you need a static set of interpolating key frames. There are no requirements for music to be involved.

How Rocket Works

Rocket data is a collection of named groups (“tracks”) containing key frames. Each key frame contains a row number (int), value (float) and interpolation type (enum/byte). The row number is a time unit. This is translated to seconds based on a configured rows per second value. Rows per second is normally adjusted based on the music such as beats per minute. The row resolution will then be a grid that helps the user to place key frames accurately in sync with the music.

The rocket client can be used in three different modes:

  • Editor mode: Use the socket connector to connect to an external editor. The editor should ideally already be opened and you have loaded an xml file containing all the key frame data. When the client connects it will download all the key frames from the editor and will keep synchronizing the data as you edit the key frames.

  • Playback: Editor Data: The client will load the xml file created by the editor and play it back. This is a perfectly valid option in the final product if you don’t care that others can easily inspect and edit the project file and you are not constrained by file size limits. (Project files are xml with lots of additional metadata used by the editor)

  • Playback: Exported: In editor mode you can select “export remote” that will tell the client to save all the current tracks in separate files in a binary format. This mode loads and plays back this data. The main purpose if this option is to vastly reduce the size of all the key frame data.

Interpolation Types

The client library will do all the interpolation calculations for you. The rocket protocol is supposed to be as simple as possible. If you need any other interpolation types you can for example use linear interpolation and apply a formula on these values.

Supported interpolation modes are:
  • Step: Key frame produces a constant value)

  • Linear: Linear interpolation between key frames

  • Smooth: Interpolates key frames using: t * t * (3 - 2 * t)

  • Ramp: Interpolates key frame using: t^2

Using the Client

First of all you have to create a controller. This class keeps track of the current time. We currently only implement a basic TimeController. If you want music playback you will have to implement your own controller by extending the base Controller class. The reason for this is simply that we don’t want to lock users into using a specific library. The support for audio playback in Python is also a bit flaky and almost always requires some third party binary dependency. The easiest way to get music playback up and running is probably to use the mixer module in pygame, but this requires SDL libraries to be installed.

Quick draw loop setup:

import time
from rocket.rocket import Rocket

# Simple controller tracking time at 24 rows per second
controller = TimeController(24)

# Create the rocket client in different modes
# Editor mode (track_path: where binary track data ends up when doing a remote export)
rocket = Rocket.from_socket(controller, track_path="./data")
# Playback using the editor file
rocket = Rocket.from_project_file(controller, 'example.xml')
# Playback using binary track data
rocket = Rocket.from_files(controller, './data')

# Register some tracks
# Just register a track
rocket.track("cube:rotation")
# Register a track and store the reference for later
size_track = rocket.track("cube:size")

# Enter the draw loop
rocket.start()
while True:
    # Update inner states. The controller is manly involved in that.
    rocket.update()

    # Get the cube rotation value at the current time
    cube_rot = rocket.value("cube:rotation")

    # Get the cube size by accessing the track directly (using seconds)
    cube_size = size_track.time_value(rocket.time)
    # Get the cube size by accessing the track directly (using track location)
    cube_size = size_track.track_value(rocket.track)

    # Emulate 60 fps
    time.sleep(1.0 / 1000 * 16)

Track Names

The standard rocket editor support track names using utf-8, but this is not a 100% guarantee that other track editors also support this.

Some editors such as Rocket OpenGL editor support track grouping. Grouping is done by adding a prefix in the track name followed by a colon.

Example:

cube:rot.x
cube:rot.y
cube:rot.z

monkey:rot.x
monkey:rot.y
monkey:rot.z

The uniqueness of the track is based on the entire name, so you can re-use the same name across different groups.

Track names (after colon) should ideally be as short as possible. 12 characters is a good limit as editors either cut off the name or expand the column width with larger names. It’s common to use dot as a separator in track names as well, but this is not enforced as far as we know.

When tracks are serialized into binary format the colon is replaced with #. cube:rot.x track is save in the file cube#rot.x.track.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pyrocket-0.2.2-py3-none-any.whl (17.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page