-
Notifications
You must be signed in to change notification settings - Fork 2
/
Antescofo.py
193 lines (175 loc) · 7.95 KB
/
Antescofo.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import sublime, sublime_plugin
import sys
import os
pyosc = 1
# pyosc is the folder in our plugin
if sys.version_info < (3, 3):
sys.path.append(os.path.join(os.path.dirname(__file__), "pyosc"))
import OSC
else:
# pythonosc
sys.path.append(os.path.join(os.path.dirname(__file__), "python-osc-1.4.2"))
from pythonosc import osc_message_builder
from pythonosc import udp_client
pyosc = 0
# Extends CMD+SHIFT+p to use OSC to send to Antescofo
class OscsendCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.settings = sublime.load_settings('Antescofo.sublime-settings')
address = self.settings.get('antescofoip', 'localhost')
port = self.settings.get('antescofoport', 5678)
# Walk through each region in the selection
for region in self.view.sel():
# If no region, then just send the line!
if region.empty():
# Expand the region to the full line it resides on, excluding the newline
line = self.view.line(region)
# Extract the string for the line, and add a newline
Contents = self.view.substr(line) + '\n'
else :
# if region, then send the region
# Get the selected text
Contents = self.view.substr(region) + '\n'
# Send OSC message
if pyosc:
## Send using pyosc
client = OSC.OSCClient()
client.connect((address, port))
oscmsg = OSC.OSCMessage('/antescofo/cmd')
oscmsg.append('playstring')
oscmsg.append(Contents)
client.send(oscmsg)
else :
client = udp_client.UDPClient(address, port)
oscmsg = osc_message_builder.OscMessageBuilder(address = "/antescofo/cmd")
oscmsg.add_arg("playstring")
oscmsg.add_arg(Contents)
oscmsg = oscmsg.build()
client.send(oscmsg)
# ctrl+s to START Antescofo via OSC
class StartantescofoCommand(sublime_plugin.WindowCommand):
def run(self):
print('Starting Antescofo...')
self.settings = sublime.load_settings('Antescofo.sublime-settings')
address = self.settings.get('antescofoip', 'localhost')
port = self.settings.get('antescofoport', 5678)
if pyosc:
## Use pyosc
client = OSC.OSCClient()
client.connect((address, port))
oscmsg = OSC.OSCMessage("/antescofo/cmd")
oscmsg.append('start')
client.send(oscmsg)
else:
## use pythonosc
client = udp_client.UDPClient(address, port)
oscmsg = osc_message_builder.OscMessageBuilder(address = "/antescofo/cmd")
oscmsg.add_arg("start")
oscmsg = oscmsg.build()
client.send(oscmsg)
# ctrl+shift+s for STARTFROMLABEL via OSC
# The cursor must be on an EVENT containing a Label!
class StartfromlabelCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.settings = sublime.load_settings('Antescofo.sublime-settings')
address = self.settings.get('antescofoip', 'localhost')
port = self.settings.get('antescofoport', 5678)
# Walk through each region in the selection
for region in self.view.sel():
# If no region, then it is a LINE
if region.empty():
# Expand the region to the full line it resides on, excluding the newline
line = self.view.line(region)
scope_name = 'source.antescofo labeled.textslm label.antescofo '
label = None
for r in self.view.find_by_selector(scope_name):
if r.intersects(line):
label = self.view.substr(r)
print(label)
break
if label is None :
print('Antescofo: No label at current position!')
else:
print('Antescofo startfromlabel ', label)
if pyosc:
## Use pyosc
client = OSC.OSCClient()
client.connect((address, port))
oscmsg = OSC.OSCMessage("/antescofo/cmd")
oscmsg.append('startfromlabel')
oscmsg.append(label)
client.send(oscmsg)
else:
## use pythonosc
client = udp_client.UDPClient(address, port)
oscmsg = osc_message_builder.OscMessageBuilder(address = "/antescofo/cmd")
oscmsg.add_arg("startfromlabel")
oscmsg.add_arg(label)
oscmsg = oscmsg.build()
client.send(oscmsg)
else :
print('Antescofo Startfromlabel Command does not work on Regions!')
# ctrl+s to START Antescofo via OSC
class StopantescofoCommand(sublime_plugin.WindowCommand):
def run(self):
print('Stop Antescofo...')
self.settings = sublime.load_settings('Antescofo.sublime-settings')
address = self.settings.get('antescofoip', 'localhost')
port = self.settings.get('antescofoport', 5678)
if pyosc:
## Use pyosc
client = OSC.OSCClient()
client.connect((address, port))
oscmsg = OSC.OSCMessage("/antescofo/cmd")
oscmsg.append('stop')
client.send(oscmsg)
else:
## use pythonosc
client = udp_client.UDPClient(address, port)
oscmsg = osc_message_builder.OscMessageBuilder(address = "/antescofo/cmd")
oscmsg.add_arg("stop")
oscmsg = oscmsg.build()
client.send(oscmsg)
# ctrl+l to load current file in Antescofo
class Loadantescofo(sublime_plugin.TextCommand):
def run(self, edit):
self.settings = sublime.load_settings('Antescofo.sublime-settings')
address = self.settings.get('antescofoip', 'localhost')
port = self.settings.get('antescofoport', 5678)
ascographip = self.settings.get('ascographip', 'localhost')
ascographport = self.settings.get('ascographport', 6789)
filename = self.view.file_name()
print('Antescofo Loading ', filename)
if pyosc:
# We are in Sublime 2!
# send to Antescofo Max/Pd objects
client = OSC.OSCClient()
client.connect((address, port))
oscmsg = OSC.OSCMessage('/antescofo/cmd')
oscmsg.append('score')
oscmsg.append(filename)
client.send(oscmsg)
# send to Ascograph
ascoclient = OSC.OSCClient()
ascoclient.connect((ascographip, ascographport))
oscmsg2 = OSC.OSCMessage('/antescofo/loadscore')
oscmsg2.append(filename)
ascoclient.send(oscmsg2)
else:
# We are in Sublime 3 / use PythonOSC
#filename = self.window.extract_variables()['file']
# Send to Antescofo object in Max/Pd
client = udp_client.UDPClient(address, port)
oscmsg = osc_message_builder.OscMessageBuilder(address = "/antescofo/cmd")
oscmsg.add_arg("score")
oscmsg.add_arg(filename)
oscmsg = oscmsg.build()
client.send(oscmsg)
# Send to AscoGraph if any
ascoclient = udp_client.UDPClient(ascographip, ascographport)
oscmsg2 = osc_message_builder.OscMessageBuilder(address = "/antescofo/loadscore")
oscmsg2.add_arg(filename)
oscmsg2 = oscmsg2.build()
ascoclient.send(oscmsg2)
## We can use is_dirty to check if they are unsaved changes! TODO
#print('File_name is ', self.view.file_name(), ' is_dirty? ', self.view.is_dirty())