A Python interface for Antescofo, the score following and synchronous programming language for music
Project description
Antescofo Python Interface
A comprehensive Python library for communicating with and controlling Antescofo, the score following and synchronous programming language for music developed at IRCAM.
Features
- OSC Communication: Send and receive OSC messages to/from Antescofo instances
- Transport Control: Load scores, start/stop playback, control tempo, navigate events
- Event System: Subscribe to and handle events from Antescofo (tempo changes, beat positions, action traces, etc.)
- Score Generation: Programmatically create and manipulate Antescofo score files
- Data Types: Python representations of Antescofo data structures (Tabs, Maps)
- Type-Safe: Well-typed API with comprehensive error handling
- Easy to Use: Pythonic interface with context manager support
Installation
From PyPI (when published)
pip install antescofo
From Source
git clone https://github.com/yourusername/antescofo.git
cd antescofo
pip install -e .
Dependencies
- Python >= 3.8
- python-osc >= 1.8.0
Quick Start
Basic Control
from antescofo import AntescofoClient
# Create and connect to Antescofo
with AntescofoClient(host="localhost", port=5678) as client:
# Load a score
client.load_score("path/to/score.asco.txt")
# Start playback
client.start()
# Set tempo
client.set_tempo(120)
# Wait for some time
client.wait(5)
# Stop playback
client.stop()
Event Listening
from antescofo import AntescofoClient, EventType
# Create client with receive port to get events
client = AntescofoClient(
host="localhost",
port=5678,
receive_port=9999 # Port to receive events on
)
# Define event handlers
def on_tempo_change(event):
print(f"Tempo changed to: {event.data}")
def on_beat_position(event):
print(f"Beat position: {event.data}")
# Connect and subscribe
client.connect()
client.on(EventType.TEMPO, on_tempo_change)
client.on(EventType.BEAT_POSITION, on_beat_position)
# Start playback
client.start()
# Keep running to receive events
try:
while True:
client.wait(0.1)
except KeyboardInterrupt:
client.stop()
client.disconnect()
Score Generation
from antescofo import ScoreBuilder
# Build a score programmatically
builder = (
ScoreBuilder()
.comment("My Generated Score")
.event("NOTE", 1.0, "C4 60")
.action('print "Hello from C4"')
.event("NOTE", 0.5, "D4 62")
.action('$tempo := 120')
.event("NOTE", 0.5, "E4 64")
.action('print "Finished!"')
)
# Save to file
builder.save("generated_score.asco.txt")
# Or get the score object
score = builder.get_score()
print(score)
Documentation
AntescofoClient
The main interface for controlling Antescofo.
client = AntescofoClient(
host="localhost", # Antescofo host
port=5678, # Port to send messages to
receive_port=None, # Port to receive events (optional)
auto_connect=False # Auto-connect on initialization
)
Transport Control Methods
connect()- Connect to Antescofodisconnect()- Disconnect from Antescofoload_score(filepath)- Load a score filestart()- Start playbackstop()- Stop playbackpause()- Pause playbackresume()- Resume paused playbacknext_event()- Skip to next eventprev_event()- Go to previous eventset_tempo(bpm)- Set tempo in BPM
Event Subscription
on(event_type, handler)- Subscribe to eventsoff(event_type, handler)- Unsubscribe from events
OSC Communication
send_osc(address, *args)- Send OSC messageenable_osc_communication(enable=True)- Enable/disable OSCconfigure_ascograph(host, port)- Configure Ascograph connection
Event Types
Available event types:
EventType.STOP- Playback stoppedEventType.BEAT_POSITION- Beat position updateEventType.RNOW- Relative time updateEventType.TEMPO- Tempo changeEventType.PITCH- Pitch detectionEventType.ACTION_TRACE- Action execution traceEventType.LOAD_SCORE- Score loaded
Data Types
Tab (Array/List)
from antescofo import Tab
# Create a tab
tab = Tab([1, 2, 3, 4])
# Access elements
print(tab[0]) # 1
# Append
tab.append(5)
# Convert to/from list
lst = tab.to_list()
tab2 = Tab.from_list([10, 20, 30])
Map (Dictionary)
from antescofo import Map
# Create a map
m = Map({"tempo": 120, "volume": 0.8})
# Access values
print(m["tempo"]) # 120
# Set values
m["pitch"] = 440
# Convert to/from dict
d = m.to_dict()
m2 = Map.from_dict({"key": "value"})
Score Generation
ScoreFile
from antescofo import ScoreFile
# Create a new score
score = ScoreFile()
# Add content
score.add_comment("My Score")
score.add_event("NOTE", 1.0, "C4 60")
score.add_action('print "Hello"')
# Insert other files
score.insert_file("library.asco.txt")
score.insert_file_once("utilities.asco.txt")
# Add conditionals
score.add_conditional(
"@arch_darwin",
'print "macOS"',
'print "Other OS"'
)
# Save
score.save("myscore.asco.txt")
# Load existing score
loaded = ScoreFile.load("existing.asco.txt")
ScoreBuilder
from antescofo import ScoreBuilder
# Use builder pattern for fluent API
builder = (
ScoreBuilder()
.comment("Generated Score")
.event("NOTE", 1.0, "C4 60")
.action('print "Hello"')
.insert("library.asco.txt")
.raw("@global $x := 42") # Add raw line
)
builder.save("output.asco.txt")
Examples
See the examples/ directory for complete examples:
basic_control.py- Basic playback controlevent_listening.py- Event subscription and handlingscore_generation.py- Programmatic score creation
Running Tests
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run with coverage
pytest --cov=antescofo --cov-report=html
Architecture
The library is organized into several modules:
client.py- High-levelAntescofoClientinterfaceosc.py- OSC communication layer using python-oscevents.py- Event system and dispatchertypes.py- Data type mappings (Tab, Map, etc.)score.py- Score file reading/writing/generationconstants.py- Constants and message typesexceptions.py- Custom exceptions
Requirements
- Antescofo: You need a running Antescofo instance (Max/MSP external, PureData external, or standalone)
- OSC Setup: Configure Antescofo to communicate via OSC
- Default Antescofo port: 5678
- Default Ascograph port: 6789
Antescofo Resources
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License - see LICENSE file for details
Authors
- Antescofo Python Interface Contributors
Acknowledgments
- Antescofo was developed by Arshia Cont and the team at IRCAM
- This Python interface is an independent project to facilitate Python integration
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file antescofo-0.1.1.tar.gz.
File metadata
- Download URL: antescofo-0.1.1.tar.gz
- Upload date:
- Size: 23.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15e001e1443f8b5a9a72004cea69b4ecdaa64dc03fff6cb05bc4e27e2d502b75
|
|
| MD5 |
7b7d74db8d865b5986068554d3b56a09
|
|
| BLAKE2b-256 |
7044ef665389511b036409150403fdab5f9bf62eeb21c94d0a6a24e9f91bcfaf
|
File details
Details for the file antescofo-0.1.1-py3-none-any.whl.
File metadata
- Download URL: antescofo-0.1.1-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88fceea19db549ade4019f1d4d5082f74d3d23a2309e7807da6ff8794d1ee278
|
|
| MD5 |
94f38a9f07e97d7afb527910a96ed1ae
|
|
| BLAKE2b-256 |
3e31fe9ea45e9447726161106af207fce17f9e2b9856d89f965f9846e08791f1
|