antescofo
Antescofo Python Interface
A Python library for communicating with and controlling Antescofo, the score following and synchronous programming language for music.
- Basic usage:
>>> from antescofo import AntescofoClient >>> client = AntescofoClient() >>> client.connect() >>> client.load_score("myscore.asco.txt") >>> client.start()
For more examples, see the examples/ directory.
- class antescofo.ActionTraceEvent(action_name: str, trace_type: str, father_name: str, now: float, rnow: float, message: str, raw_address: str = None)[source]
Specialized event for action traces.
- class antescofo.AntescofoClient(host: str = 'localhost', port: int = None, receive_port: int | None = None, auto_connect: bool = False)[source]
High-level client for controlling an Antescofo instance.
This class provides a Pythonic interface to Antescofo, allowing you to: - Load and control score playback - Send OSC messages - Subscribe to events - Control transport (start, stop, tempo, etc.)
Example
>>> client = AntescofoClient() >>> client.connect() >>> client.load_score("myscore.asco.txt") >>> client.start() >>> client.set_tempo(120) >>> client.stop() >>> client.disconnect()
- Or use as a context manager:
>>> with AntescofoClient() as client: ... client.load_score("myscore.asco.txt") ... client.start()
- configure_ascograph(host: str = 'localhost', port: int = 6789)[source]
Configure Ascograph communication.
- Parameters:
host – Ascograph host
port – Ascograph port (default: 6789)
- connect()[source]
Establish connection to Antescofo.
Creates the OSC communicator and starts receiving if a receive port is configured.
- enable_incoming_osc(enable: bool = True)[source]
Enable or disable incoming OSC messages.
- Parameters:
enable – Whether to enable (True) or disable (False)
- enable_osc_communication(enable: bool = True)[source]
Enable or disable OSC communication with Ascograph/external systems.
- Parameters:
enable – Whether to enable (True) or disable (False)
- load_score(filepath: str | Path)[source]
Load an Antescofo score file.
- Parameters:
filepath – Path to the score file (.asco.txt or similar)
- off(event_type: EventType | str | None, handler: Callable[[Event], None])[source]
Unsubscribe from events.
- Parameters:
event_type – Type of event to unsubscribe from
handler – Handler to remove
- on(event_type: EventType | str | None, handler: Callable[[Event], None])[source]
Subscribe to events from Antescofo.
- Parameters:
event_type – Type of event to subscribe to (EventType enum or string), or None to subscribe to all events
handler – Callback function that takes an Event object
Example
>>> def on_tempo_change(event): ... print(f"Tempo changed to: {event.data}") >>> client.on(EventType.TEMPO, on_tempo_change) >>> # or >>> client.on("tempo", on_tempo_change)
- send_osc(address: str, *args)[source]
Send an OSC message to Antescofo.
- Parameters:
address – OSC address (will be prefixed with /antescofo/ if not present)
*args – Message arguments
- class antescofo.Event(event_type: EventType, data: Any, raw_address: str = None)[source]
Represents an event received from Antescofo.
- class antescofo.EventDispatcher[source]
Manages event subscriptions and dispatching.
Allows subscribing to specific event types and dispatching events to registered handlers.
- dispatch(event: Event) None[source]
Dispatch an event to all registered handlers.
- Parameters:
event – Event to dispatch
- class antescofo.Map(data: Dict[str, Any] = None)[source]
Represents an Antescofo map (associative array/dictionary).
Maps are collections of key-value pairs.
- class antescofo.OSCCommunicator(host: str = 'localhost', send_port: int = 5678, receive_port: int | None = None)[source]
Handles OSC communication with Antescofo.
Manages sending messages to Antescofo and receiving messages from it.
- send(address: str, *args)[source]
Send an OSC message.
- Parameters:
address – OSC address pattern (e.g., “/antescofo/tempo”)
*args – Message arguments
- send_raw(*args)[source]
Send raw arguments without an address (for internal Antescofo commands).
- Parameters:
*args – Message arguments (first arg typically the command name)
- class antescofo.ScoreBuilder[source]
Builder pattern for constructing Antescofo scores programmatically.
Example
>>> builder = ScoreBuilder() >>> builder.comment("My Score") >>> builder.event("NOTE", 1.0, "C4 60") >>> builder.action("print Hello") >>> builder.save("myscore.asco.txt")
- action(action: str) ScoreBuilder[source]
Add an action.
- Parameters:
action – Action code
- Returns:
Self for chaining
- comment(text: str) ScoreBuilder[source]
Add a comment.
- Parameters:
text – Comment text
- Returns:
Self for chaining
- event(event_type: str, duration: float | None = None, attributes: str | None = None) ScoreBuilder[source]
Add an event.
- Parameters:
event_type – Event type
duration – Duration
attributes – Attributes
- Returns:
Self for chaining
- insert(filepath: str | Path) ScoreBuilder[source]
Insert a file.
- Parameters:
filepath – Path to insert
- Returns:
Self for chaining
- insert_once(filepath: str | Path) ScoreBuilder[source]
Insert a file once.
- Parameters:
filepath – Path to insert
- Returns:
Self for chaining
- raw(line: str) ScoreBuilder[source]
Add a raw line.
- Parameters:
line – Line to add
- Returns:
Self for chaining
- class antescofo.ScoreFile(content: str = '')[source]
Represents an Antescofo score file.
Provides methods to read, write, and manipulate score files.
- add_comment(comment: str)[source]
Add a comment line.
- Parameters:
comment – Comment text (will be prefixed with ;)
- add_conditional(condition: str, if_block: str, else_block: str | None = None)[source]
Add a conditional block.
- Parameters:
condition – Condition expression
if_block – Code to execute if condition is true
else_block – Optional code to execute if condition is false
- add_event(event_type: str, duration: float | None = None, attributes: str | None = None)[source]
Add an event to the score.
- Parameters:
event_type – Type of event (e.g., “NOTE”, “CHORD”)
duration – Duration of the event
attributes – Additional attributes
- insert(index: int, line: str)[source]
Insert a line at a specific position.
- Parameters:
index – Position to insert at
line – Line to insert
- insert_file(filepath: str | Path, quote_if_spaces: bool = True)[source]
Insert a @insert directive for another file.
- Parameters:
filepath – Path to the file to insert
quote_if_spaces – Whether to quote the filepath if it contains spaces
- insert_file_once(filepath: str | Path, quote_if_spaces: bool = True)[source]
Insert a @insert_once directive for another file.
- Parameters:
filepath – Path to the file to insert
quote_if_spaces – Whether to quote the filepath if it contains spaces
- classmethod load(filepath: str | Path) ScoreFile[source]
Load a score file from disk.
- Parameters:
filepath – Path to the score file
- Returns:
ScoreFile object
- Raises:
ScoreError – If the file cannot be read
- save(filepath: str | Path)[source]
Save the score to a file.
- Parameters:
filepath – Path to save the score to
- Raises:
ScoreError – If the file cannot be written
- class antescofo.Tab(values: List[Any] = None)[source]
Represents an Antescofo tab (array/list).
Tabs are ordered collections of values that can be of mixed types.
- antescofo.from_osc_value(value: Any) int | float | str | Tab | Map | List | Dict[source]
Convert an OSC value to a Python value.
- Parameters:
value – OSC value to convert
- Returns:
Python value
- antescofo.get_config_value(key: str, default: Any = None) Any[source]
Get a specific configuration value.
- Parameters:
key – Configuration key
default – Default value if key not found
- Returns:
Configuration value
- antescofo.init_config(force: bool = False) Path[source]
Initialize user configuration with defaults.
Creates ~/.config/antescofo/config.json with default settings.
- Parameters:
force – If True, overwrite existing config
- Returns:
Path to the config file
- antescofo.load_config(reload: bool = False) Dict[str, Any][source]
Load user configuration.
- Parameters:
reload – If True, bypass cache and reload from disk
- Returns:
Configuration dictionary
- antescofo.resolve_score_path(score_name: str) Path[source]
Resolve a score file path.
If score_name is relative, looks in the default score directory. If absolute, uses as-is.
- Parameters:
score_name – Score filename or path
- Returns:
Resolved absolute path
- antescofo.save_config(config: Dict[str, Any])[source]
Save configuration to file.
- Parameters:
config – Configuration dictionary to save