### Folder Class - Usage Examples Source: https://docs.cycling74.com/apiref/js/folder Examples demonstrating how to use the Folder class. ```APIDOC ## Folder Class Examples ### Creating a Folder Object ``` f = new Folder("patches"); // would try to find the patches folder in the search path f = new Folder("Disk:/folder1/folder2"); // uses an absolute path ``` ### Filtering Files by Type ``` f.typelist = ["iLaF", "maxb", "TEXT"]; // typical max files ``` ### Iterating Through Files ``` while (!f.end) { post(f.filename); post(); f.next(); } ``` ### Closing a Folder Object ``` f.close(); ``` ``` -------------------------------- ### Example Usage Source: https://docs.cycling74.com/apiref/js/maxstring Examples demonstrating how to use the MaxString class. ```APIDOC ## Example 1: Reading String Content ### Description This example shows how to bind to a Max string by name and read its contents. ### Code ```javascript function string(str_name) { var max_str = new MaxString(); max_str.name = str_name; // binds to the Max `string` by name var contents = max_str.stringify(); // read the value of the string } ``` ## Example 2: Modifying String Content ### Description This example demonstrates how to read a Max string's content, modify it using JavaScript string functions, and then update the Max string. ### Code ```javascript function lower(str_name) { var max_str = new MaxString(); max_str.name = str_name; // binds to the Max `string` by name var js_str = max_str.stringify(); // get the value of the string js_str = js_str.toLowerCase(); // regular JavaScript string functions max_str.parse(js_str); // set the string's new value } ``` ``` -------------------------------- ### Start Audio Processing Source: https://docs.cycling74.com/reference/adc~ The 'start' command globally enables audio processing for all loaded patches within the application. ```APIDOC ## START ### Description Turns on audio processing in all loaded patches. ### Method N/A (Command-line or internal object command) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### MaxobjListener Example Usage Source: https://docs.cycling74.com/apiref/js/maxobjlistener An example demonstrating how to use the MaxobjListener to observe changes in an object's attribute. ```APIDOC ### Example ```javascript function valuechanged(data) { post("value changed!\n"); if (data.attrname) { post("attrname: " + data.attrname + "\n"); } post("new value: " + data.value + "\n"); } var ob = this.patcher.getnamed("someobject"); var l = new MaxobjListener(ob, "patching_rect", valuechanged); ``` ``` -------------------------------- ### Initialize jit.world and jit.gl.mesh Source: https://docs.cycling74.com/learn/articles/jitterchapter00i_generating-geometry Set up the basic environment for rendering 3D geometry. Ensure lighting is enabled for the mesh. ```maxpat jit.world @lighting_enable 1 ``` -------------------------------- ### Get List of Installed Fonts Source: https://docs.cycling74.com/apiref/js/mgraphics Retrieves a list of all fonts installed on the system. Returns an array of strings. ```javascript getfontlist(): string[]; ``` -------------------------------- ### Loading Audio into jit.buffer~ Source: https://docs.cycling74.com/learn/articles/jitterchapter48 This example shows how to load audio data from a sound file into a jit.buffer~ object. The jit.buffer~ object acts as a Jitter wrapper for MSP's buffer~, allowing data to be accessed and manipulated as Jitter matrices. ```maxpat talk.aiff ``` -------------------------------- ### Query Track Mute Status using Max for Live Objects Source: https://docs.cycling74.com/userguide/m4l/live_api Use live.path to get the ID of a track, then use live.object with a 'get' message to query its mute status. Track numbering starts from 0. ```max path live_set tracks 2 ``` ```max id N ``` ```max get mute ``` ```max mute 0 ``` -------------------------------- ### Get AIFF loop points with info~ Source: https://docs.cycling74.com/learn/articles/07_samplingchapter03 The info~ object can query a buffer~ containing an AIFF file to retrieve its embedded loop start and end points. These values can then be sent to groove~. ```max info~ ``` -------------------------------- ### Initialize File with constructor arguments Source: https://docs.cycling74.com/apiref/js/file Creates and opens a file reference immediately using constructor parameters. ```javascript var f = new File("myfile.txt", "write"); post(f.isopen); // true, if myfile.txt is in the Max search path f.close(); ``` -------------------------------- ### Observe Live API Property (Mute) Source: https://docs.cycling74.com/userguide/m4l/live_api Construct a message to query a Live API property. This example queries the 'mute' property of Track 3. Ensure track numbering starts from 0. ```max-msp path live_set tracks 3 ``` ```max-msp property mute ``` -------------------------------- ### Sample Object - Overview Source: https://docs.cycling74.com/reference/gen_dsp_sample This section provides an overview of the 'sample' object, its purpose, and how to construct it. ```APIDOC ## sample ### Description Linear interpolated multi-channel lookup of a data/buffer object. The first argument should be a name of a data or buffer object in the gen patcher. The second argument specifies the number of output channels. The last inlet specifies a channel offset (default 0). ### Constructors * { arguments={name, channels}, inlets={index, channel_offset} } * { arguments={name}, inlets={index, channel_offset} } * { arguments={name, channels}, inlets={phase, channel_offset} } * { arguments={name}, inlets={phase, channel_offset} } * { arguments={name, channels}, inlets={signal, channel_offset} } * { arguments={name}, inlets={signal, channel_offset} } * { arguments={name, channels}, inlets={wave_phase, wave_start, wave_end, channel_offset} } * { arguments={name}, inlets={wave_phase, wave_start, wave_end, channel_offset} } ``` -------------------------------- ### Create and Configure jit.window Object Source: https://docs.cycling74.com/learn/articles/jitterchapter47 Instantiate a jit.window object for display and set its attributes. Ensure the name matches the OpenGL drawing context. Enable idlemousing to track mouse events. ```javascript // create a [jit.window] object for our display // (this is the object we'll listen to): var mywindow = new JitterObject("jit.window","ListenWindow"); // turn off depth testing... we're using blending instead: mywindow.depthbuffer = 0; // turn ON idlemousing... we want to listen for it: mywindow.idlemouse = 1; ``` -------------------------------- ### Call Live API Function (Fire Clip) Source: https://docs.cycling74.com/userguide/m4l/live_api Construct a message to call a Live API function. This example calls the 'fire' function on Clip Slot 1 of Track 1. Ensure numbering starts from 0. ```max-msp path live_set tracks 1 clip_slots 1 ``` ```max-msp call fire ``` -------------------------------- ### Interpolating Release with jit.release~ Source: https://docs.cycling74.com/learn/articles/jitterchapter48 This patch demonstrates interpolating audio data using jit.release~ in mode 1. It uses jit.buffer~ to load audio and a qmetro to control the data rate. Experiment with the 'period', 'length ratio', and 'start' controls to alter the playback. ```maxpat "interpolating" ``` -------------------------------- ### Start playback with specified time and duration Source: https://docs.cycling74.com/reference/play~ The 'start' message followed by a start time in milliseconds moves to that position and begins playing. Optional end time and duration arguments can be provided. If start time is greater than end time, playback is reversed. ```maxpat start start-time [list] end-time [list] duration [list] ``` -------------------------------- ### Start Marker API Source: https://docs.cycling74.com/apiref/lom/clip Set the start marker of a clip. ```APIDOC ## SET /start_marker ### Description Sets the start marker of the clip in beats. This value cannot be set behind the end marker. ### Method SET ### Endpoint /start_marker ### Parameters #### Request Body - **start_marker** (float) - Required - The start marker position in beats. ### Request Example ```json { "start_marker": 0.5 } ``` ### Response #### Success Response (200) - **None** ### Response Example ```json {} ``` ``` -------------------------------- ### Instantiate and Use LiveAPI Source: https://docs.cycling74.com/apiref/js/liveapi Demonstrates creating a LiveAPI instance, accessing its properties, and setting up a callback. Ensure the LiveAPI object is not created in the high-priority thread; use defer or deferlow if necessary. ```javascript var api = new LiveAPI(sample_callback, "live_set tracks 0"); if (!api) { post("no api object\n"); return; } post("api.mode", api.mode ? "follows path" : "follows object", "\n"); post("api.id is", api.id, "\n"); post("api.path is", api.path, "\n"); post("api.children are", api.children, "\n"); post('api.getcount("devices")', api.getcount("devices"), "\n"); api.property = "mute"; post("api.property is", api.property, "\n"); post("type of", api.property, "is", api.proptype, "\n"); function sample_callback(args) { post("callback called with arguments:", args, "\n"); } ``` -------------------------------- ### GET Request Source: https://docs.cycling74.com/reference/maxurl Sends an HTTP GET request to the specified URL. ```APIDOC ## GET Request ### Description Sends an HTTP GET request to the specified URL. ### Method GET ### Endpoint /url ### Arguments - **url** (list) - The URL to send the GET request to. ``` -------------------------------- ### Set up Syphon Server for Video Streaming Source: https://docs.cycling74.com/userguide/jitter/video Create a 'jit.gl.syphonserver' object to stream Jitter textures via Syphon. Ensure '@output_texture' is enabled in jit.world. ```maxpat jit.world @output_texture 1 jit.gl.syphonserver ``` -------------------------------- ### start Message Source: https://docs.cycling74.com/reference/detonate The 'start' message initiates the playback of the score, sending out the first delta time. ```APIDOC ## start Message ### Description Begins playing back the score by sending out the first delta time. After this message, 'next' messages can be used to control the playback of subsequent events. ### Method Message ### Endpoint N/A (Object message) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example `start` ### Response #### Success Response (200) Outputs the first delta time of the score. #### Response Example (Outputs delta time value) ``` -------------------------------- ### Start Time API Source: https://docs.cycling74.com/apiref/lom/clip Retrieve the start time of the clip relative to the global song time. ```APIDOC ## GET /start_time ### Description Retrieves the start time of the clip relative to the global song time, in beats. For Arrangement View clips, this is the offset within the arrangement. For Session View clips, this is the time the clip was started. ### Method GET ### Endpoint /start_time ### Parameters None ### Response #### Success Response (200) - **start_time** (float) - The start time of the clip in beats. ### Response Example ```json { "start_time": 16.0 } ``` ``` -------------------------------- ### Create and Configure jit.gl.render Object Source: https://docs.cycling74.com/learn/articles/jitterchapter47 Set up a jit.gl.render object for drawing into the specified window. Configure projection, background color, and erase behavior for the rendering context. ```javascript // create a [jit.gl.render] object for drawing into our window: var myrender = new JitterObject("jit.gl.render","ListenWindow"); // use a 2-dimensional projection: myrender.ortho = 2; // set background to black with full erase opacity (no trails): myrender.erase_color = [0,0,0,1]; ``` -------------------------------- ### Navigate to Live Set using live.path Source: https://docs.cycling74.com/userguide/m4l/live_api_overview Use `goto live_set` to navigate to the Live set. live.path sends the object ID to its left outlet. ```maxpat live.path goto live_set ``` -------------------------------- ### SQLResult Example Usage Source: https://docs.cycling74.com/apiref/js/sqlresult An example function demonstrating how to iterate through and print all values from an SQLResult object. ```APIDOC ### Example ```javascript function print_everything(sqlres) { var numrecs = sqlres.numrecords() var numflds = sqlres.numfields() var field_names = new Array() for (var i = 0; i < numflds; i++) { field_names[i] = sqlres.fieldname(i) } for (var i = 0; i < numrecs; i++) { for (var j = 0; j < numflds; j++) { post( "Rec: ", i, " field ", field_names[j], " value ", sqlres.value(j, i), "\n" ) } } } ``` ``` -------------------------------- ### Start Audio Processing in Current Patch Source: https://docs.cycling74.com/reference/adc~ The 'startwindow' command enables audio processing specifically within the current patch and its subpatches, while disabling it in all other patches. ```APIDOC ## STARTWINDOW ### Description Turns on audio processing only in the patch in which this adc~ is located, and in subpatches of that patch. Turns off audio processing in all other patches. ### Method N/A (Command-line or internal object command) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Set up Spout Sender for Video Streaming Source: https://docs.cycling74.com/userguide/jitter/video Create a 'jit.gl.spoutsender' object to stream Jitter textures via Spout. Ensure '@output_texture' is enabled in jit.world. ```maxpat jit.world @output_texture 1 jit.gl.spoutsender ``` -------------------------------- ### Construct a ParameterInfoProvider instance Source: https://docs.cycling74.com/apiref/js/parameterinfoprovider Initialize a new provider, optionally passing a callback function for change notifications. ```javascript new ParameterInfoProvider(fn?: Function); ``` -------------------------------- ### Start Recording with jit.avc Source: https://docs.cycling74.com/learn/articles/jitterchapter23 Use the 'record' message to start recording with your DV device via jit.avc. Ensure the connection is open first. ```maxpat record ``` -------------------------------- ### Example of OpenGL drawing with glbegin Source: https://docs.cycling74.com/apiref/js/sketch Demonstrates using glbegin to draw axes with glvertex. This example assumes a global 'sketch' object is available. ```javascript var sx = 1.0; var sy = 1.0; var tx = 0.0; var ty = 0.0; function draw() { // refers to the global "sketch" object sketch.glclear(); sket.glcolor(1, 0, 0); sketch.glbegin("lines"); // draw x axis glvertex(Math.min(tx + sx * -1, -1), ty, 0); glvertex(Math.max(tx + sx * 1, 1), ty, 0); // draw y axis glvertex(tx, Math.min(ty + sy * -1, -1), 0); glvertex(tx, Math.max(ty + sy * 1, 1), 0); } ``` -------------------------------- ### Buffer~ - Open Source: https://docs.cycling74.com/reference/buffer~ Opens the buffer~ sample display window or brings it to the front if already open. ```APIDOC ## POST /buffer~/open ### Description Opens the buffer~ sample display window or brings it to the front if it is already open. ### Method POST ### Endpoint /buffer~/open ``` -------------------------------- ### Creating a Task Source: https://docs.cycling74.com/apiref/js/task Initialize a new Task instance with a function, context, and arguments. ```javascript function ticker(a, b, c) { post("tick") } args = new Array(3) args[0] = 1 args[1] = 2 args[2] = 3 t = new Task(ticker, this, args) ``` ```javascript new Task(fn: Function, obj?: object, args?: any[]); ``` -------------------------------- ### Making an HTTP GET Request Source: https://docs.cycling74.com/apiref/js/xmlhttprequest Use this to initiate an HTTP GET request. The `onreadystatechange` handler is crucial for processing the response when the request is complete. ```javascript var req = new XMLHttpRequest(); req.open("GET", "https://api.example.com/data"); req.onreadystatechange = function() { if (this.readyState == 4) { post("Response: " + this.responseText + "\n"); } }; req.send(); ``` -------------------------------- ### Implement a 4-source video mixer in GLSL Source: https://docs.cycling74.com/learn/articles/jitterchapter43 A basic fragment shader example demonstrating how to perform pointwise multiplication and accumulation of four input vectors. ```GLSL uniform vec4 a; uniform vec4 b; uniform vec4 c; uniform vec4 d; void main (void) { vec4 input0; vec4 input1; vec4 input2; vec4 input3; vec4 output; output = a*input0 + b*input1 + c*input2 + d*input3; } ``` -------------------------------- ### Example: Disconnect Two Toggle Objects Source: https://docs.cycling74.com/apiref/js/patcher Shows how to disconnect two previously connected toggle objects. This example first establishes a connection and then removes it. ```javascript var p = this.patcher; var a = p.newobject("toggle", 122, 90, 15, 0); var b = p.newobject("toggle", 122, 140, 15, 0); p.connect(a, 0, b, 0); p.disconnect(a, 0, b, 0); ``` -------------------------------- ### MGraphics Paint Function Example Source: https://docs.cycling74.com/userguide/custom_ui_objects A basic example of a paint function using MGraphics to draw a rectangle. This function is called by Max when the object needs redrawing. ```javascript // Implement this somewhere in your custom drawing code function paint() { mgraphics.rectangle(-0.2, 0.2, 0.2, -0.2) mgraphics.fill() } ``` -------------------------------- ### Example: Connect Two Toggle Objects Source: https://docs.cycling74.com/apiref/js/patcher Illustrates how to create two toggle objects and connect the outlet of the first to the inlet of the second using the `connect` method. ```javascript var p = this.patcher; var a = p.newobject("toggle", 122, 90, 15, 0); var b = p.newobject("toggle", 122, 140, 15, 0); p.connect(a, 0, b, 0); ``` -------------------------------- ### Get Property from Live Object using live.object Source: https://docs.cycling74.com/userguide/m4l/live_api_overview Use `get` messages with live.object to retrieve properties of a Live object. The object ID should be received from live.path. ```maxpat get name ``` -------------------------------- ### Open Help File Source: https://docs.cycling74.com/apiref/js/maxobj Display the help file for a Max object, if one exists, by calling the `help` method. ```javascript help(): void; ``` -------------------------------- ### Max/MSP: Resetting and Starting Playback Source: https://docs.cycling74.com/learn/articles/datachapter03 This code segment demonstrates how to reset a patch and initiate playback by controlling a toggle object. It's used when starting the recording process. ```maxmsp sel 1 trigger clear clear 0 ``` -------------------------------- ### Drawing and Hit-Testing with Multiple Paths Source: https://docs.cycling74.com/learn/articles/03-hit-testing This example initializes multiple paths, appends them to the drawing context, and performs hit-testing using mouse coordinates. It utilizes `copy_path()` to store paths and `append_path()` to add them for drawing and interaction. ```javascript mgraphics.init(); mgraphics.relative_coords = 0; let paths = []; let idle_pos = undefined; function paint() { if (paths.length === 0) { initialize_paths(mgraphics); } paths.forEach((path, idx) => { mgraphics.append_path(path); mgraphics.set_source_rgba(0.1, 0.1, 0.1, 0.6); if (idle_pos !== undefined) { if (mgraphics.in_fill(idle_pos)) { mgraphics.set_source_rgba(0.9, 0.1, 0.1, 0.9); } } mgraphics.fill(); }); } function initialize_paths(mgraphics) { let [width, height] = mgraphics.size; for (let i = 0; i < 250; i++) { mgraphics.ellipse( width * Math.random(), height * Math.random(), 10 + Math.random() * 40, 10 + Math.random() * 40 ); paths.push(mgraphics.copy_path()); mgraphics.new_path(); // start from a fresh path next time we call mgraphics.ellipse } } function onidle(x, y) { idle_pos = [x, y]; mgraphics.redraw(); } function onidleout() { idle_pos = undefined; mgraphics.redraw(); } ``` -------------------------------- ### Load and Play Video with jit.playlist Source: https://docs.cycling74.com/learn/articles/jitterchapter00c_display-a-video Use jit.playlist to load videos and connect its output to jit.world for playback. Ensure jit.world rendering is enabled with a toggle. ```maxpat jit.playlist ``` -------------------------------- ### Get VST Latency Source: https://docs.cycling74.com/learn/articles/16_pluginchapter01 Query the plug-in's latency in samples by sending the message 'get -10' to the vst~ object. The latency value is returned as a negative number. ```max get -10 ``` -------------------------------- ### JavaScript Reference Error Example Source: https://docs.cycling74.com/learn/articles/javascriptchapter01 This example shows a reference error resulting from a misspelled function name. The Max Console will report a Javascript ReferenceError, indicating that the command is not defined. ```javascript js • Hi There!!! js • [popu.js] Javascript ReferenceError: pst is not defined, line 15 js • error axlling function bang [popu.js] ``` -------------------------------- ### Graphics Contexts Source: https://docs.cycling74.com/userguide/jitter/graphics_processing Learn how to create and manage graphics contexts for rendering in Max. This includes using jit.world for windowed contexts, jit.pworld for in-patcher contexts, and understanding context naming and offscreen rendering with jit.gl.node. ```APIDOC ## Graphics Contexts In order to draw, you must have some place to draw to. The Max object `jit.world` is the simplest way to get a graphics context. This object wraps together many other, lower level objects. The two most important of these objects are `jit.window`, which creates a graphics context in a separate window, and `jit.gl.render`, which can be used to direct Max to render a single frame of graphics. While `jit.world` creates a separate window, you can also use the `jit.pworld` object, which has similar functionality as `jit.world`, except the graphics context appears as a frame in the Max patcher. ### Context Names Most graphics processing objects (usually with the `jit.gl` prefix) refer to their parent context by name. Even if you don't assign an explicit name to your graphics context using the `@name` attribute, Max will create a unique name automatically when you create it. If you add a graphics processing object to your patcher, by default it will bind to whatever graphics context is available in the current patcher. However, if you have multiple graphics contexts in a single patcher, you can use an attribute to bind the object specifically to a particular context. Most objects use the `@drawto` attribute to choose their parent context explicitly. An alternative way to set `@drawto` is to provide the context name as the first argument following the object name. ### Offscreen Contexts It is possible to hide the window created by `jit.world` using the `@visible` attribute. However, the best way to create an offscreen context is with the `jit.gl.node` object. Using the `@name` attribute, you can give `jit.gl.node` a name, and then use the `@drawto` attribute to bind objects to the `jit.gl.node`. Finally, enable texture capture with `@capture 1` on the `jit.gl.node` object. In this configuration, the `jit.gl.node` object functions as an offscreen render target. The output of `jit.gl.node` will be a texture to which you can add postprocessing. Note that here, since the `jit.gl.gridshape` is drawing to the context owned by `jit.gl.node`, the shape is not visible in the window context owned by `jit.world`. However, for `jit.gl.node` to function, it must still have its own parent context. So the `jit.world` object must be present for this patcher to function. ``` -------------------------------- ### Initialize Folder Object Source: https://docs.cycling74.com/apiref/js/folder Create a new Folder instance using either a relative search path or an absolute path. ```javascript f = new Folder("patches"); // would try to find the patches folder in the search path f = new Folder("Disk:/folder1/folder2"); // uses an absolute path ``` -------------------------------- ### JavaScript Syntax Error Example Source: https://docs.cycling74.com/learn/articles/javascriptchapter01 This example demonstrates a syntax error caused by unbalanced parentheses. The Max Console will report a Javascript SyntaxError, indicating the line where the error occurred. ```javascript js • [popu.js] Javascript SyntaxError: syntax error, line 15 source line: post(; ```