-
Notifications
You must be signed in to change notification settings - Fork 12
/
arturia_playlist.py
99 lines (73 loc) · 2.75 KB
/
arturia_playlist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""Module to support tracking and selecting playlist tracks."""
import channels
import patterns
import playlist
_current_playlist_track = 1
def current_playlist_track():
"""Returns the current playlist track."""
global _current_playlist_track
return _current_playlist_track
def _deselect_all_playlist_track():
for i in range(1, playlist.trackCount()):
track_name = playlist.getTrackName(i)
if track_name.startswith('* '):
playlist.setTrackName(i, track_name[2:])
def strip_pattern_name(name):
if name.startswith('* '):
return name[2:]
return name
def _select_pattern_named(name):
for i in range(1, patterns.patternCount() + 1):
if strip_pattern_name(patterns.getPatternName(i)) == name:
patterns.jumpToPattern(i)
return
# No pattern found
patterns.deselectAll()
def set_playlist_track(track):
global _current_playlist_track
_current_playlist_track = track
name = playlist.getTrackName(track)
if name.startswith('* '):
return
_deselect_all_playlist_track()
_select_pattern_named(name)
playlist.setTrackName(track, '* ' + name)
def _all_pattern_names():
return (strip_pattern_name(patterns.getPatternName(i)) for i in range(1, patterns.patternCount() + 1))
def next_pattern_name():
"""Returns the next suggested pattern name."""
pattern_names = _all_pattern_names()
# If there are N patterns, then at most, N+1 instruments
selected = channels.selectedChannel()
name = strip_pattern_name(channels.getChannelName(selected))
if name not in pattern_names:
return name
for i in range(1, patterns.patternCount() + 1):
suggested = '%s [%d]' % (name, i)
if suggested not in pattern_names:
return suggested
return '%s [%d]' % (name, patterns.patternCount() + 1)
def _select_playlist_track_named(name):
base = name.split(' [')[0]
for i in range(1, playlist.trackCount()):
track_name = get_playlist_track_name(i)
if track_name == base:
set_playlist_track(i)
return
def _select_channel_from_name(name):
base = name.split(' [')[0]
for i in range(channels.channelCount()):
if base == channels.getChannelName(i):
channels.deselectAll()
channels.selectChannel(i, 1)
return True
return False
def get_playlist_track_name(track):
"""Returns the playlist track name."""
return strip_pattern_name(playlist.getTrackName(track))
def select_playlist_track_from_pattern(pattern_index):
"""Select the specified pattern"""
name = get_playlist_track_name(pattern_index)
_select_channel_from_name(name)
_select_playlist_track_named(name)
patterns.jumpToPattern(pattern_index)