Skip to content

Commit

Permalink
add brand new hover documentation generated from ckdoc and python script
Browse files Browse the repository at this point in the history
  • Loading branch information
terryzfeng committed Jul 18, 2024
1 parent 7320556 commit 26f753d
Show file tree
Hide file tree
Showing 9 changed files with 4,680 additions and 5,853 deletions.
126 changes: 126 additions & 0 deletions scripts/convertDocumentation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Generate all CKDoc documentation for Monaco Editor
#
# Steps TODO:
# 1. Get the latest CKDOC gen-all.ck script and generate json documentation
# Link: https://github.com/ccrma/chuck/blob/main/src/scripts/ckdoc/gen-all.ck
# - Uncomment line 166 to generate json format
# - Change line 169 to put everything in `./json` folder
# 2. Run the ckdoc generator with `chuck gen-all.ck`
# 3. Run this script `python convertDocumentation.py`
#
# written 7/17/2024
# terry feng - [email protected]

import json

# where the final ckdoc is outputted!!!
OUTPUT_FILE_PATH = "../src/components/monaco/ckdoc.json"

file_dir = "./json/"
files = [
'base.json',
'ugens-basic.json',
'ugens-filters.json',
'ugens-stk.json',
'ugens-advanced.json',
'uanae.json',
'ai.json',
'io.json',
'utils.json',
'chugins.json'
]

CKDOC_URL = 'https://chuck.stanford.edu/doc/reference/'

# function to build string of arguments
def argumentString(argArray):
if (len(argArray) == 0):
return ""

argString = ""
for arg in argArray:
argString += f"{arg['type']} {arg['name']}, "
return argString[:-2]

# function convert ckdoc json to hover documentation format
def convertToHoverDoc(obj):
entry = {}
# title
entry['title'] = f"**{obj['title']}**"
# description
entry["description"] = obj["description"]
# constructors
if ("constructors" in obj and len(obj["constructors"]) > 0):
constructors = ["```chuck\n" + constr["constructor"] + "(" + argumentString(constr["arguments"]) + ")\n```\n" + constr["description"] for constr in obj["constructors"]]
entry["constructors"] = ["**Constructors:**"] + constructors
else:
entry["constructors"] = []
# examples
if ("examples" in obj and len(obj["examples"]) > 0):
example_md = [f"[{url.split('/')[-1]}]({url})" for url in obj["examples"]]
entry["examples"] = [ "Examples: \t " + ", ".join(example_md) ]
else:
entry["examples"] = []
functions = []
if ("member functions" in obj):
for func in obj["member functions"]:
# functions +=
functions.append(f"```chuck\n{func['return type']} {func['member function']}({argumentString(func['arguments'])})\n```\n{func['description']}")
if ("static member functions" in obj):
for func in obj["static member functions"]:
functions.append(f"```chuck\n{func['return type']} {func['static member function']}({argumentString(func['arguments'])})\n```\n{func['description']}")
if (len(functions) > 0):
entry["functions"] = ["**Methods:**"] + functions
else:
entry["functions"] = []
# link
entry["link"] = f"[More...]({obj['link']})"

return entry


###############################################################################
# MAIN
###############################################################################

# hand-written ugen names
titles = open('titles.json', encoding='utf-8')
title_data = json.load(titles)

# generated ckdoc json
data = {}
for file in files:
with open(file_dir + file, encoding='utf-8') as f:
file_data = json.load(f)
groups = file_data["groups"]
for group in groups:
name = group["name"]
group["link"] = CKDOC_URL + file.split(".")[0] + ".html#" + name
group["title"] = title_data[name]
data[name] = group

assert(len(data) == len(title_data))

# output json for ide hover documentation
output = {}

# iterate through ckdoc for conversion
for entry in data:
output[entry] = convertToHoverDoc(dict(data[entry]))

# re-iterate for custom CKDoc fixes (common ones)
for entry in output:
if "Osc" in entry and entry != "Osc":
output[entry]["functions"] = output["Osc"]["functions"] + output["UGen"]["functions"][1:] + output[entry]["functions"][1:]
if "LiSa" in entry and entry != "LiSa":
output[entry]["functions"] = output["LiSa"]["functions"]
if entry == "SndBuf2":
output[entry]["functions"] = output["SndBuf"]["functions"]
if entry == "Gain":
output[entry]["functions"] = output["UGen"]["functions"]

# Alphabetize and write to .json file
output = dict(sorted(output.items()))

with open(OUTPUT_FILE_PATH, 'w', encoding='utf-8') as f:
json.dump(output, f, ensure_ascii=False, indent=4)
2 changes: 1 addition & 1 deletion scripts/examplesToJSON.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re

# TODO: Mini Audicle examples path here
CHUCK_EXAMPLES_PATH= "YOUR/PATH/HERE"
CHUCK_EXAMPLES_PATH = "YOUR/PATH/HERE"
OUTPUT_JSON_FILE = "../public/examples/moreExamples.json"

# Chuck examples Web URL
Expand Down
181 changes: 181 additions & 0 deletions scripts/titles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
{
"Object": "ChucK Base Object Class",
"Event": "ChucK Event Class",
"Shred": "ChucK Shred Class",
"Math": "Math Class Library",
"Machine": "ChucK Virtual Machine Interface",
"Std": "ChucK Standard Library",
"string": "String Class",
"@array": "Array Class",
"UGen": "Unit Generator Base Class",
"Gain": "Gain",
"Impulse": "Impulse Generator",
"Step": "Step Generator",
"SndBuf": "Sound Buffer",
"SndBuf2": "Sound Buffer (Stereo)",
"ADSR": "ADSR Envelope",
"Delay": "Digital Delay Line",
"DelayL": "Linear Interpolating Delay Line",
"DelayA": "All-Pass Interpolating Delay Line",
"Echo": "Echo Effect",
"Noise": "White Noise Generator",
"CNoise": "Colored Noise Generator",
"Osc": "Oscillator Base Class",
"SinOsc": "Sine Wave Oscillator",
"TriOsc": "Triangle Wave Oscillator",
"SawOsc": "Sawtooth Wave Oscillator",
"PulseOsc": "Pulse Width Oscillator",
"SqrOsc": "Square Wave Oscillator",
"Phasor": "Phasor Oscillator",
"HalfRect": "Half Wave Rectifier",
"FullRect": "Full Wave Rectifier",
"Chugraph": "Subgraph-Based User-Created UGen",
"Chugen": "User-Created UGen",
"UGen_Multi": "Multi-Channel UGen",
"UGen_Stereo": "Stereo UGen",
"Mix2": "Stereo to Mono UGen",
"Pan2": "Mono to Stereo Panner",
"FilterBasic": "Filter Base Class",
"LPF": "Low-Pass Filter",
"HPF": "High-Pass Filter",
"BPF": "Band-Pass Filter",
"BRF": "Band-Reject Filter",
"BiQuad": "BiQuad Filter",
"ResonZ": "Resonant Filter",
"OnePole": "One-Pole Filter",
"OneZero": "One-Zero Filter",
"TwoPole": "Two-Pole Filter",
"TwoZero": "Two-Zero Filter",
"PoleZero": "Pole-Zero Filter",
"JCRev": "John Chowning's Reverberator",
"NRev": "CCRMA's NRev Reverberator",
"PRCRev": "Perry Cook's Simple Reverberator",
"Chorus": "Chorus Effect",
"Modulate": "Modulation Effect",
"PitShift": "Pitch Shift Effect",
"SubNoise": "Sub-Sampling Noise Generator",
"BLT": "Band-Limited Oscillator Base Class",
"Blit": "Band-Limited Impulse Train",
"BlitSaw": "Band-Limited Sawtooth Oscillator",
"BlitSquare": "Band-Limited Square Wave Oscillator",
"FilterStk": "STK Filter Base Class",
"WvIn": "Audio File Input",
"WaveLoop": "Audio File Looping",
"WvOut": "Audio File Output",
"WvOut2": "Audio File Output (Stereo)",
"StkInstrument": "STK Instrument",
"BandedWG": "Banded Waveguide",
"BeeThree": "STK Organ",
"BlowBotl": "STK Blow Bottle",
"BlowHole": "STK Blow Hole",
"Bowed": "STK Bowed String",
"Brass": "STK Brass",
"Clarinet": "STK Clarinet",
"Flute": "STK Flute",
"FM": "STK FM Synthesis",
"HevyMetl": "STK Heavy Metal",
"Mandolin": "STK Mandolin",
"ModalBar": "STK Modal Bar",
"Moog": "STK Moog",
"PercFlut": "STK Percussive Flute",
"Rhodey": "STK Rhodes Piano",
"Saxofony": "STK Saxophone",
"Shakers": "STK Shakers",
"Sitar": "STK Sitar",
"StifKarp": "STK Stiff Karplus-Strong",
"VoicForm": "STK Voice Formant",
"Wurley": "STK Wurlitzer",
"OscIn": "OSC Input",
"OscOut": "OSC Output",
"OscMsg": "OSC Message",
"ConsoleInput": "Console Input Utility",
"StringTokenizer": "String Tokenizer",
"Type": "ChucK Type Class",
"UAna": "Unit Analyzer Base Class",
"UAnaBlob": "Unit Analyzer Blob",
"Chroma": "Chroma Feature Analyzer",
"Flux": "Spectral Flux Analyzer",
"Sigmund": "Sigmund",
"Spectacle": "Spectral Delay and EQ",
"KrstlChr": "STK Crystal Choir",
"FMVoices": "STK FM Voices",
"HnkyTonk": "STK Honky Tonk Piano",
"FrencHrn": "STK French Horn",
"TubeBell": "STK Tubular Bell",
"LiSa": "Live Sampling UGen",
"LiSa2": "Live Sampling UGen 2-channel",
"LiSa6": "Live Sampling UGen 6-channel",
"LiSa8": "Live Sampling UGen 8-channel",
"LiSa10": "Live Sampling UGen 10-channel",
"LiSa16": "Live Sampling UGen 16-channel",
"GenX": "Makegen Lookup Table",
"Gen5": "Makegen Exponential Line Segment Table",
"Gen7": "Makegen Line Segment Table",
"Gen9": "Makegen Inharmonic Sinusoidal Lookup Table",
"Gen10": "Makegen Sinusoidal Lookup Table",
"Gen17": "Makegen Chebyshev Polynomial Lookup Table",
"CurveTable": "Curve Table",
"WarpTable": "Warp Table",
"Dyno": "Dynamics Processor",
"Kurtosis": "Kurtosis Analyzer",
"Centroid": "Spectral Centroid Analyzer",
"FileIO": "File Input and Output",
"KBHit": "Keyboard Hit",
"Hid": "Human-Interface Device (HID)",
"HidMsg": "Human-Interface Device (HID) Message",
"MFCC": "Mel-Frequency Cepstral Coefficients",
"RMS": "Root Mean Square",
"RollOff": "Spectral Rolloff",
"SFM": "Spectral Flatness Measure",
"ZeroX": "Zero Crossing Detector",
"AutoCorr": "Autocorrelation",
"DCT": "Discrete Cosine Transform",
"FeatureCollector": "UAna Feature Collector",
"FFT": "Fast Fourier Transform",
"Flip": "Signal Flip",
"IDCT": "Inverse Discrete Cosine Transform",
"IFFT": "Inverse Fast Fourier Transform",
"UnFlip": "Signal Unflip",
"XCorr": "Cross Correlation",
"Windowing": "Windowing Function",
"MLP": "Multi-Layer Perceptron",
"KNN": "K-Nearest Neighbors",
"KNN2": "K-Nearest Neighbors (Labels)",
"HMM": "Hidden Markov Model",
"SVM": "Support Vector Machine",
"Word2Vec": "Word2Vec",
"PCA": "Principal Component Analyzer",
"Wekinator": "Wekinator",
"AI": "AI Class Library",
"IO": "Input/Output Base Class",
"SerialIO": "Serial Input/Output",
"MidiOut": "MIDI Output",
"MidiIn": "MIDI Input",
"MidiMsg": "MIDI Message",
"MidiFileIn": "MIDI File Input",
"CKDoc": "ChucK Documentation Generator",
"ABSaturator": "Abel/Berners' Saturator",
"AmbPan3": "3D Ambisonic Panner",
"Bitcrusher": "Bitcrusher Effect",
"Elliptic": "Elliptic Filter",
"ExpDelay": "Exponential Delay",
"ExpEnv": "Exponential Envelope",
"Envelope": "Envelope Generator",
"FIR": "Finite Impulse Response Filter",
"FoldbackSaturator": "Foldback Saturator",
"GVerb": "GVerb Reverb",
"KasFilter": "Kassel Filter",
"MagicSine": "Magic Sine Oscillator",
"Mesh2D": "2D Digital Waveguide Mesh",
"Multicomb": "Multi-Comb Filter",
"Pan4": "4-Channel Panner",
"Pan8": "8-Channel Panner",
"Pan16": "16-Channel Panner",
"PitchTrack": "Pitch Tracker",
"PowerADSR": "Power ADSR Envelope",
"RegEx": "Regular Expression",
"WinFuncEnv": "Window Function Envelope",
"WPDiodeLadder": "WPD Diode Ladder Filter",
"WPKorg35": "WPD Korg 35 Filter"
}

7 changes: 5 additions & 2 deletions src/components/monaco/chuck-lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import { monaco } from "./monacoLite";
import { chuck_modules, chuck_libraries } from "./chuck-modules";
import ckdocJSON from "./output.json";
import ckdocJSON from "./ckdoc.json";

// Documentation Type for ckdoc
interface docType {
title: string;
description: string;
constructors: string[];
functions: string[];
examples: string[];
link: string;
Expand Down Expand Up @@ -363,7 +364,9 @@ monaco.languages.registerHoverProvider("chuck", {
value: word_doc.description,
},
{
supportHtml: true,
value: word_doc.constructors.join("\n\n"),
},
{
value: word_doc.functions.join("\n\n"),
},
{
Expand Down
Loading

0 comments on commit 26f753d

Please sign in to comment.