Skip to content

Commit 10b5fef

Browse files
committed
Create dedicated documentation for Timeline synchronisation
1 parent f892057 commit 10b5fef

File tree

2 files changed

+63
-28
lines changed

2 files changed

+63
-28
lines changed

docs/timelines/index.md

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Timelines
22

3+
## About timelines
4+
35
A `Timeline` schedules and executes events following a clock.
46

57
By default, a Timeline creates its own internal clock at a specified tempo:
68

79
```python
8-
timeline = iso.Timeline(120)
10+
timeline = Timeline(120)
911
timeline.run()
1012
```
1113

@@ -17,27 +19,7 @@ You can set and query the tempo using the `tempo` property:
1719
140
1820
```
1921

20-
## Sync from clock in
21-
22-
A Timeline can be synchronised from an external MIDI clock:
23-
24-
```python
25-
midi_in = MidiInputDevice()
26-
timeline = iso.Timeline(clock_source=midi_in)
27-
timeline.run()
28-
```
29-
30-
MIDI `start` and `stop` events will be followed. Querying the timeline's `tempo` will give an estimate of the current bpm based on a moving average.
31-
32-
## Sync to clock out
33-
34-
You can also drive external MIDI clocks from a Timeline, by specifying the `send_clock` argument when creating the output device.
35-
36-
```python
37-
output_device = iso.MidiOutputDevice(send_clock=True)
38-
timeline = iso.Timeline(120, output_device=output_device)
39-
timeline.run()
40-
```
22+
To synchronise the timeline with an external device, see [Synchronisation](synchronisation.md).
4123

4224
## Scheduling events
4325

@@ -48,11 +30,11 @@ Scheduling events is done by passing a dict to the `Timeline.schedule()` method,
4830
# Play a series of 5 notes with random velocities.
4931
# Delay by 1 beat before playback.
5032
#--------------------------------------------------------------------------------
51-
timeline = iso.Timeline(120)
33+
timeline = Timeline(120)
5234
timeline.schedule({
53-
"note": iso.PSequence([ 60, 67, 72, 77, 84 ], 1),
35+
"note": PSequence([ 60, 67, 72, 77, 84 ], 1),
5436
"duration": 0.5,
55-
"amplitude": iso.PWhite(0, 128)
37+
"amplitude": PWhite(0, 128)
5638
}, delay=1)
5739
timeline.run()
5840
```
@@ -66,7 +48,7 @@ To limit the number of iterations of an event, pass the `count` property:
6648

6749
```
6850
timeline.schedule({
69-
"note": iso.PSeries(0, 1) + 60
51+
"note": PSeries(0, 1) + 60
7052
}, count=4)
7153
```
7254

@@ -78,5 +60,4 @@ High-precision scheduling in Python is inherently limited by Python's global int
7860

7961
## Nonlinear time
8062

81-
Time warping and nonlinear time is a work in progress.
82-
63+
Time warping and nonlinear time is a work in progress.

docs/timelines/synchronisation.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Timelines: Synchronisation with external clocks
2+
3+
isobar can synchronise with external clocks in a few different ways.
4+
5+
- MIDI: [Sync from MIDI clock in](#sync-from-midi-clock-in)
6+
- MIDI: [Sync to MIDI clock out](#sync-to-midi-clock-out)
7+
- [Ableton Link Clock](#ableton-link-clock)
8+
9+
## Sync from MIDI clock in
10+
11+
A Timeline can be synchronised from an external MIDI clock:
12+
13+
```python
14+
midi_in = MidiInputDevice()
15+
timeline = Timeline(clock_source=midi_in)
16+
timeline.run()
17+
```
18+
19+
MIDI transport events will be obeyed:
20+
21+
- `start` starts the timeline playback from time = 0
22+
- `stop` stops the timeline
23+
- `continue` resumes playback from wherever it was stopped
24+
25+
When synchronised to an external MIDI clock, querying the timeline's `tempo` will give an estimate of the current bpm based on a moving average.
26+
27+
## Sync to MIDI clock out
28+
29+
You can also drive external MIDI clocks from a Timeline, by specifying the `send_clock` argument when creating the output device.
30+
31+
```python
32+
output_device = MidiOutputDevice(send_clock=True)
33+
timeline = Timeline(120, output_device=output_device)
34+
try:
35+
timeline.run()
36+
except KeyboardInterrupt:
37+
# When ctrl-c is pressed, stop the timeline, which sends a MIDI `stop`
38+
# transport message to the external device.
39+
timeline.stop()
40+
```
41+
42+
## Ableton Link clock
43+
44+
Playback can be synchronised with Ableton Live or other devices that support [Ableton Link](https://www.ableton.com/en/link/) clocking. Other Link processes on the same computer, or on the local network, are automatically detected.
45+
46+
Ensure that Ableton Live is running on the network with `Link` enabled. Run the below example, and you should hear that it is synchronised with Live's playback.
47+
48+
```
49+
timeline = Timeline(clock_source="link")
50+
timeline.schedule({
51+
"note": 60
52+
}, quantize=1)
53+
timeline.run()
54+
```

0 commit comments

Comments
 (0)