Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created November 23, 2013 21:08
Show Gist options
  • Save zeffii/7619982 to your computer and use it in GitHub Desktop.
Save zeffii/7619982 to your computer and use it in GitHub Desktop.
# this needs would replace Ck_wav_write in ChucK.py
class Ck_wav_write(sublime_plugin.TextCommand):
def run(self, edit):
# the only requirement is (for now) that a copy of wav_writer.ck be located
# in the same folder as the .ck you're trying to record.
""" // wav_writer.ck
Std.atoi(me.arg(0)) => int num_seconds;
me.arg(1) => string wav_name;
dac => Gain g => WvOut2 w => blackhole;
wav_name + ".wav" => w.wavFilename;
1 => w.record;
num_seconds::second => now;
0 => w.record;
"""
view = self.view
file_path = view.file_name()
file_name = os.path.basename(file_path)
print(file_path)
"""
we can use the text editor view as a faux console
the following lines should be equivalent. The first example would be normal
chuck shell usage, the second is what you type on a line in a chuck file to
record 20 seconds to a stereo wave called "new_wavename"
- > chuck somefile.ck wav_writer.ck:20:new_wavename
- // %> 20:new_wavename (hit ctrl+shift+w, or your chosen keycombo)
"""
selections = view.sel()
if selections[0].a == selections[0].b:
try:
sel = view.line(selections[0])
selection = view.substr(sel)
# get the last portion after the comment, split and strip
found_content = selection.rsplit("//", 1)[1]
sides = found_content.split("%>")
right_side = sides[1].strip()
song_duration, wav_name = [s.strip() for s in right_side.split(":")]
# compile commands for subprocess.
cc = ["wav_writer.ck", str(song_duration), wav_name]
record_commands = ":".join(cc)
chuck_init_wav = ["chuck", file_name, record_commands, "-s"]
print(chuck_init_wav)
p = subprocess.Popen(chuck_init_wav,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True).communicate()
for line in p:
print(line.decode())
except:
print("try: // %> 20:new_wavename")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment