View on GitHub

apicultor

API.Cultor: Another BigData approach to sound collections

APICultor Cloud Instrument

A modern, real-time sound synthesis system with OSC control and MIR-based sound selection.

Overview

The Cloud Instrument is a complete refactored and modernized version of the original APICultor cloud instrument. It provides real-time audio synthesis controlled via OSC (Open Sound Control) messages, with intelligent sound selection based on Music Information Retrieval (MIR) descriptors.

Key Features

Quick Start

1. Installation

See INSTALL.md for detailed installation instructions.

Quick install:

# Install dependencies
pip install python-osc python-rtmidi librosa ffmpeg-python requests

# Optional: Install freesound-python
pip install "freesound-python @ git+https://github.com/MTG/freesound-python.git"

2. Configuration

Create a configuration file cloud_instrument_config.json:

{
  "osc": {
    "host": "127.0.0.1",
    "port": 9001,
    "enable_logging": true
  },
  "audio": {
    "backend": "supercollider",
    "sample_rate": 44100,
    "buffer_size": 512
  },
  "midi": {
    "enabled": true,
    "virtual_port": true,
    "client_name": "CloudInstrument"
  },
  "database": {
    "default_provider": "freesound",
    "freesound_api_key": "${FREESOUND_API_KEY}"
  },
  "enabled_modules": ["database"]
}

For Freesound API access, get your API key from Freesound APIv2.

3. Run the Application

Modern version (recommended):

python CloudInstrument_modern.py

Legacy version:

python CloudInstrument.py

With custom configuration:

python CloudInstrument_modern.py -c my_config.json

With command-line overrides:

python CloudInstrument_modern.py --osc-port 9002 --audio-backend pyo --no-midi

Architecture

Modern Architecture (2025 Refactor)

cloud_instrument/
โ”œโ”€โ”€ core/                    # Core application components
โ”‚   โ”œโ”€โ”€ application.py          # Main app orchestrator
โ”‚   โ”œโ”€โ”€ config.py              # Configuration management
โ”‚   โ”œโ”€โ”€ events.py              # Event system
โ”‚   โ””โ”€โ”€ exceptions.py          # Exception hierarchy
โ”œโ”€โ”€ osc/                     # OSC system
โ”‚   โ”œโ”€โ”€ server.py              # OSC server + mock fallback
โ”‚   โ”œโ”€โ”€ handlers.py            # Message routing & handling
โ”‚   โ””โ”€โ”€ messages.py            # OSC message types
โ”œโ”€โ”€ audio/                   # Audio system
โ”‚   โ”œโ”€โ”€ manager.py             # Audio coordinator
โ”‚   โ”œโ”€โ”€ backends.py            # Audio server implementations
โ”‚   โ”œโ”€โ”€ effects.py             # Audio effects
โ”‚   โ””โ”€โ”€ interfaces.py          # Audio interfaces
โ”œโ”€โ”€ midi/                    # MIDI system
โ”‚   โ”œโ”€โ”€ manager.py             # MIDI coordinator
โ”‚   โ”œโ”€โ”€ controllers.py         # Hardware controller support
โ”‚   โ””โ”€โ”€ messages.py            # MIDI message handling
โ””โ”€โ”€ tests/                   # Modern test suite
    โ”œโ”€โ”€ test_config.py
    โ””โ”€โ”€ test_osc.py

Key Improvements

Aspect Before (Legacy) After (Modern)
Python Version 2.7 3.8+ with type annotations
Architecture Monolithic script Modular, event-driven
Configuration Hard-coded Flexible JSON + environment variables
Error Handling Basic Comprehensive with graceful degradation
Testing Minimal pytest with mocks and fixtures
Documentation Limited Complete with examples

Usage

OSC Messages

The Cloud Instrument responds to various OSC messages:

Audio Effects

/fx/volume [float]           # Volume control (0.0-1.0)
/fx/pan [float]              # Pan position (-1.0 to 1.0)
/fx/reverb [room_size, damping]  # Reverb parameters
/fx/delay [time, feedback]   # Delay effect
/fx/filter [freq, resonance, type]  # Filter control

MIR Parameters

/mir/tempo [bpm]             # Target tempo
/mir/centroid [hz]           # Spectral centroid target
/mir/duration [seconds]      # Target duration
/mir/hfc [value]             # High frequency content

Sound Control

/sound/search [query]        # Search sound database
/sound/play [id]             # Play sound by ID
/sound/stop                  # Stop playback

System Control

/system/status               # Get system status
/system/shutdown             # Graceful shutdown

MIDI Controllers

Supported Controllers

Yaeltex Controller:

Akai Midimix:

Generic Controllers:

Audio Backends

SuperCollider

# Start SuperCollider first
sclang -D apicultor_synth.scd

Pyo

# Python-based audio processing
python CloudInstrument_modern.py --audio-backend pyo

Mock (Testing)

# No audio hardware required
python CloudInstrument_modern.py --audio-backend mock

User Interfaces

OpenStageControl UI

Load ui/apicultor-ui.json in OpenStageControl with OSC receiving port 7000.

UI ArCiTec

MIDI Controllers

Yaeltex Custom Controller

Yaeltex Controller

Custom Yaeltex MIDI controllers provide dedicated hardware control.

Controller

Modes

MIR Mode: MIR Mode

Synth Mode: Synth Mode

Audio Processing Chain

Input โ†’ Effects Chain โ†’ Output
        โ†“
freeze โ†’ vibrato โ†’ pan โ†’ pitch shift โ†’ filters โ†’ delay โ†’ reverb

Development

Testing

# Run test suite
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=cloud_instrument --cov-report=html

# Test specific component
pytest tests/test_osc.py -v

Type Checking

mypy cloud_instrument/

Code Formatting

black cloud_instrument/
flake8 cloud_instrument/

Command Line Options

python CloudInstrument_modern.py --help

Options include:

Environment Variables

Set environment variables for sensitive configuration:

export FREESOUND_API_KEY="your_api_key_here"
export APICULTOR_LOG_LEVEL="DEBUG"

Troubleshooting

Common Issues

OSC not working:

MIDI not working:

Audio backend issues:

Logging

Enable debug logging for troubleshooting:

python CloudInstrument_modern.py --verbose

Or set in configuration:

{
  "logging": {
    "level": "DEBUG",
    "file": "cloud_instrument.log"
  }
}

Integration

APICultor Plugin System

The Cloud Instrument integrates with the APICultor plugin system:

from cloud_instrument import CloudInstrumentApp

app = CloudInstrumentApp("config.json")
app.run()

External Applications

Send OSC messages from any application:

from pythonosc.udp_client import SimpleUDPClient

client = SimpleUDPClient("127.0.0.1", 9001)
client.send_message("/fx/volume", 0.8)

Performance

Raspberry Pi Configuration

For optimal performance on Raspberry Pi:

# ~/.jackdrc
/usr/bin/jackd -P75 -t2000 -dalsa -dhw:S2 -p4096 -n7 -r44100 -s

Real-time Audio

Configure low-latency audio:

{
  "audio": {
    "sample_rate": 44100,
    "buffer_size": 256,
    "channels": 2
  }
}

License

Free Software shared with GPL v3. See LICENSE.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass: pytest tests/
  5. Submit a pull request

Support