Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/chuck_doc_search.py
Created November 8, 2013 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/7372852 to your computer and use it in GitHub Desktop.
Save zeffii/7372852 to your computer and use it in GitHub Desktop.
'''
chuck_doc_search.py
author: Dealga McArdle, 2013
functionality: opens webbrowser at ugen doc#ugen if ugen is valid.
sublime API docs: sublimetext.com/docs/2/api_reference.html
[1] Place this .py inside Data/Packages/User/..
[2] add the following line to you user keymap file
{ "keys": ["ctrl+shift+]"], "command": "chuck_doc_search" }
[3] to use, make a selection of for examples "ADSR", then hit ctrl+shift+]
the webbrowser should pop up
'''
import sublime, sublime_plugin
ugens = [
'dac', 'adc', 'blackhole', 'Gain', 'Noise', 'Impulse',
'Step', 'HalfRect', 'FullRect', 'ZeroX', 'BiQuad', 'Filter',
'OnePole', 'TwoPole', 'OneZero', 'TwoZero', 'PoleZero', 'LPF',
'HPF', 'BPF', 'BRF', 'ResonZ', 'FilterBasic', 'Dyno', 'DelayP',
'SndBuf', 'Phasor', 'SinOsc', 'PulseOsc', 'SqrOsc', 'TriOsc',
'SawOsc', 'GenX', 'LiSa', 'netout', 'netin', 'Pan2', 'Mix2',
'StkInstrument', 'BandedWG', 'BlowBotl', 'BlowHole', 'Bowed',
'Brass', 'Clarinet', 'Flute', 'Mandolin', 'ModalBar', 'Moog',
'Saxofony', 'Shakers', 'Sitar', 'StifKarp', 'VoicForm', 'FM',
'BeeThree', 'FMVoices', 'HevyMetl', 'PercFlut', 'Rhodey',
'TubeBell', 'Wurley', 'Delay', 'DelayA', 'DelayL', 'Echo',
'Envelope', 'ADSR', 'JCRev', 'NRev', 'PRCRev', 'Chorus',
'Modulate', 'PitShift', 'SubNoise', 'WvIn', 'WaveLoop', 'WvOut']
def open_browser(ugen):
import webbrowser
chuck_princeton = "http://chuck.cs.princeton.edu"
ugen_doc_location = chuck_princeton + "/doc/program/ugen_full.html"
webbrowser.open(ugen_doc_location + "#" + ugen)
def find_docs(ugen):
if ugen in ugens:
open_browser(ugen)
elif ugen in ["SndBuf2"]:
print("{0} is valid.. search for SndBuf instead".format(ugen))
else:
print('not a ugen, not known, or incorrect spelling')
print('could offer correct spelling, or replace it if match')
class ChuckDocSearch(sublime_plugin.TextCommand):
def run(self, edit):
if not self.enabled():
tmsg = 'you must select a ugen object'
sublime.status_message(tmsg)
return
view = self.view
sel = view.sel()[0]
ugen = view.substr(sel)
find_docs(ugen)
def enabled(self):
'''only allow 1 selection for version 0.1'''
sels = self.view.sel() # lists regions,
nsels = len(sels) # dir(sels[0]) for methods
fsel = sels[0] # first selection
if nsels == 1 and not fsel.empty():
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment