From c7abe11813f23a01bf9dc2ace0fd813132bdb292 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 12 Jul 2020 17:22:51 +0200 Subject: [PATCH] CommonJS modules --- ExampleJS/tsconfig.json | 15 ----- ExampleJSUI/tsconfig.json | 16 ----- JavaScript/ExampleJS.js | 43 ++---------- {ExampleJS => JavaScript}/ExampleJS.maxpat | 0 JavaScript/ExampleJSUI.js | 47 ++----------- .../ExampleJSUI.maxpat | 0 JavaScript/ExampleModule.js | 36 ++++++++++ Modules/ExampleModule.ts | 39 ----------- README.md | 66 +++++++++++-------- {ExampleJS => TypeScript}/ExampleJS.ts | 15 +++-- {ExampleJSUI => TypeScript}/ExampleJSUI.ts | 16 +++-- TypeScript/ExampleModule.ts | 37 +++++++++++ TypeScript/tsconfig.json | 17 +++++ .../types}/cycling74-max7-jitter.d.ts | 14 ++-- .../types}/cycling74-max7-jsui.d.ts | 37 ++++++----- .../types}/cycling74-max7.d.ts | 8 +-- 16 files changed, 192 insertions(+), 214 deletions(-) delete mode 100644 ExampleJS/tsconfig.json delete mode 100644 ExampleJSUI/tsconfig.json rename {ExampleJS => JavaScript}/ExampleJS.maxpat (100%) rename {ExampleJSUI => JavaScript}/ExampleJSUI.maxpat (100%) create mode 100644 JavaScript/ExampleModule.js delete mode 100644 Modules/ExampleModule.ts rename {ExampleJS => TypeScript}/ExampleJS.ts (69%) rename {ExampleJSUI => TypeScript}/ExampleJSUI.ts (75%) create mode 100644 TypeScript/ExampleModule.ts create mode 100644 TypeScript/tsconfig.json rename {Definitions => TypeScript/types}/cycling74-max7-jitter.d.ts (98%) rename {Definitions => TypeScript/types}/cycling74-max7-jsui.d.ts (98%) rename {Definitions => TypeScript/types}/cycling74-max7.d.ts (99%) diff --git a/ExampleJS/tsconfig.json b/ExampleJS/tsconfig.json deleted file mode 100644 index 2c1177e..0000000 --- a/ExampleJS/tsconfig.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "compilerOptions": { - "module": "system", - "target": "es3", - "noImplicitAny": false, - "sourceMap": false, - "lib": [ "es7" ], - "outFile": "../JavaScript/ExampleJS.js" - }, - "files": [ - "../Modules/ExampleModule.ts", - "ExampleJS.ts", - "../Definitions/cycling74-max7.d.ts" - ] -} \ No newline at end of file diff --git a/ExampleJSUI/tsconfig.json b/ExampleJSUI/tsconfig.json deleted file mode 100644 index bcccadf..0000000 --- a/ExampleJSUI/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "compilerOptions": { - "module": "system", - "target": "es3", - "noImplicitAny": false, - "sourceMap": false, - "lib": [ "es7" ], - "outFile": "../JavaScript/ExampleJSUI.js" - }, - "files": [ - "../Modules/ExampleModule.ts", - "ExampleJSUI.ts", - "../Definitions/cycling74-max7.d.ts", - "../Definitions/cycling74-max7-jsui.d.ts" - ] -} \ No newline at end of file diff --git a/JavaScript/ExampleJS.js b/JavaScript/ExampleJS.js index 19020e1..18e5fe3 100644 --- a/JavaScript/ExampleJS.js +++ b/JavaScript/ExampleJS.js @@ -1,44 +1,8 @@ -var ExampleModule; -(function (ExampleModule) { - // These two functions are painfully slow ;) - function colorFn(x) { - return [Math.sin(x) * 0.5 + 0.5, - Math.sin(x + 0.333 * Math.PI) * 0.5 + 0.5, - Math.sin(x + 0.666 * Math.PI) * 0.5 + 0.5, - 1.0]; - } - ExampleModule.colorFn = colorFn; - function pixelFn(x, y, t, prmA, prmB) { - var r = Math.sin(t + x * 2.0) + Math.cos(t + y * 2.0); - r += Math.sin(t + x * Math.sin(t + x * 0.02) * prmA) + Math.cos(t + y * (Math.cos(t * 0.7) * 5.0)) * prmB; - return colorFn(r + t); - } - ExampleModule.pixelFn = pixelFn; - function square(x) { - return x * x; - } - ExampleModule.square = square; - var TheClass = (function () { - function TheClass(index) { - this.index = index; - post("TheClass.constructor was called with the number parameter " + index + "\n"); - } - TheClass.prototype.getIndex = function () { - return this.index; - }; - TheClass.prototype.post = function () { - post("TheClass: post!"); - post(); - }; - return TheClass; - }()); - ExampleModule.TheClass = TheClass; -})(ExampleModule || (ExampleModule = {})); +"use strict"; +var em = require("./ExampleModule"); inlets = 1; outlets = 1; autowatch = 1; -// Only works if ExampleModule.ts is declared before ExampleJS.ts in tsconfig.json! -var em = ExampleModule; function bang() { var theObject = new em.TheClass(42); post("theObject.getIndex(): " + theObject.getIndex() + "\n"); @@ -54,3 +18,6 @@ function msg_float(v) { function msg_int(v) { outlet(0, em.square(v)); } +// .ts files with this at the end become a script usable in a [js] or [jsui] object +var module = {}; +module.exports = {}; diff --git a/ExampleJS/ExampleJS.maxpat b/JavaScript/ExampleJS.maxpat similarity index 100% rename from ExampleJS/ExampleJS.maxpat rename to JavaScript/ExampleJS.maxpat diff --git a/JavaScript/ExampleJSUI.js b/JavaScript/ExampleJSUI.js index c8ac01a..e4ab534 100644 --- a/JavaScript/ExampleJSUI.js +++ b/JavaScript/ExampleJSUI.js @@ -1,39 +1,5 @@ -var ExampleModule; -(function (ExampleModule) { - // These two functions are painfully slow ;) - function colorFn(x) { - return [Math.sin(x) * 0.5 + 0.5, - Math.sin(x + 0.333 * Math.PI) * 0.5 + 0.5, - Math.sin(x + 0.666 * Math.PI) * 0.5 + 0.5, - 1.0]; - } - ExampleModule.colorFn = colorFn; - function pixelFn(x, y, t, prmA, prmB) { - var r = Math.sin(t + x * 2.0) + Math.cos(t + y * 2.0); - r += Math.sin(t + x * Math.sin(t + x * 0.02) * prmA) + Math.cos(t + y * (Math.cos(t * 0.7) * 5.0)) * prmB; - return colorFn(r + t); - } - ExampleModule.pixelFn = pixelFn; - function square(x) { - return x * x; - } - ExampleModule.square = square; - var TheClass = (function () { - function TheClass(index) { - this.index = index; - post("TheClass.constructor was called with the number parameter " + index + "\n"); - } - TheClass.prototype.getIndex = function () { - return this.index; - }; - TheClass.prototype.post = function () { - post("TheClass: post!"); - post(); - }; - return TheClass; - }()); - ExampleModule.TheClass = TheClass; -})(ExampleModule || (ExampleModule = {})); +"use strict"; +var em = require("./ExampleModule"); inlets = 1; outlets = 1; autowatch = 1; @@ -41,15 +7,13 @@ var m = mgraphics; m.init(); m.relative_coords = 0; m.autofill = 0; -// Only works if ExampleModule.ts is declared before ExampleJS.ts in tsconfig.json! -var em = ExampleModule; var t = 0; var a = 10.0; var b = 2.0; var div = 8; function paint() { - var width = box.rect[2] - this.box.rect[0]; - var height = this.box.rect[3] - this.box.rect[1]; + var width = box.rect[2] - box.rect[0]; + var height = box.rect[3] - box.rect[1]; m.set_source_rgba(0.0, 0.0, 0.0, 1.0); m.rectangle(0, 0, width, height); m.fill(); @@ -78,3 +42,6 @@ function setRes(v) { div = Math.floor(v); m.redraw(); } +// .ts files with this at the end become a script usable in a [js] or [jsui] object +var module = {}; +module.exports = {}; diff --git a/ExampleJSUI/ExampleJSUI.maxpat b/JavaScript/ExampleJSUI.maxpat similarity index 100% rename from ExampleJSUI/ExampleJSUI.maxpat rename to JavaScript/ExampleJSUI.maxpat diff --git a/JavaScript/ExampleModule.js b/JavaScript/ExampleModule.js new file mode 100644 index 0000000..ee6b8d4 --- /dev/null +++ b/JavaScript/ExampleModule.js @@ -0,0 +1,36 @@ +"use strict"; +exports.__esModule = true; +exports.TheClass = exports.square = exports.pixelFn = exports.colorFn = void 0; +// These two functions are painfully slow ;) +function colorFn(x) { + return [Math.sin(x) * 0.5 + 0.5, + Math.sin(x + 0.333 * Math.PI) * 0.5 + 0.5, + Math.sin(x + 0.666 * Math.PI) * 0.5 + 0.5, + 1.0]; +} +exports.colorFn = colorFn; +function pixelFn(x, y, t, prmA, prmB) { + var r = Math.sin(t + x * 2.0) + Math.cos(t + y * 2.0); + r += Math.sin(t + x * Math.sin(t + x * 0.02) * prmA) + Math.cos(t + y * (Math.cos(t * 0.7) * 5.0)) * prmB; + return colorFn(r + t); +} +exports.pixelFn = pixelFn; +function square(x) { + return x * x; +} +exports.square = square; +var TheClass = /** @class */ (function () { + function TheClass(index) { + this.index = index; + post("TheClass.constructor was called with the number parameter " + index + "\n"); + } + TheClass.prototype.getIndex = function () { + return this.index; + }; + TheClass.prototype.post = function () { + post("TheClass: post!"); + post(); + }; + return TheClass; +}()); +exports.TheClass = TheClass; diff --git a/Modules/ExampleModule.ts b/Modules/ExampleModule.ts deleted file mode 100644 index b64d075..0000000 --- a/Modules/ExampleModule.ts +++ /dev/null @@ -1,39 +0,0 @@ -module ExampleModule { - - // These two functions are painfully slow ;) - export function colorFn(x: number): number[] { - return [Math.sin(x) * 0.5 + 0.5, - Math.sin(x + 0.333 * Math.PI) * 0.5 + 0.5, - Math.sin(x + 0.666 * Math.PI) * 0.5 + 0.5, - 1.0]; - } - - export function pixelFn(x: number, y: number, t: number, prmA: number, prmB: number): number[] { - let r = Math.sin(t + x * 2.0) + Math.cos(t + y * 2.0); - r += Math.sin(t + x * Math.sin(t + x * 0.02) * prmA) + Math.cos(t + y * (Math.cos(t * 0.7) * 5.0)) * prmB; - return colorFn(r + t); - } - - export function square(x: number): number { - return x * x; - } - - export class TheClass { - - private index: number; - - constructor(index: number) { - this.index = index; - post("TheClass.constructor was called with the number parameter " + index + "\n"); - } - - getIndex(): number { - return this.index; - } - - post(): void { - post("TheClass: post!"); - post(); - } - } -} diff --git a/README.md b/README.md index bd3a817..58a3fd7 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,62 @@ -***TypeScript for Cycling '74 Max / MSP / Jitter*** +TypeScript for Cycling '74 Max / MSP / Jitter +=== + +Compile TypeScript into JavaScript for use in Max. Examples show how to use modules and output a separate .js file for each .ts file. -Compile TypeScript into JavaScript for use in Max. Examples show how to use modules and concatenate everything into a single JavaScript file. Still has plenty of TODO's in the definition files, but the grunt work of writing the definitions has been done and it is useable. Expect minor bugs and missing definitions. -Follow this guide to set up Sublime Text and TypeScript: -https://cmatskas.com/getting-started-with-typescript-and-sublime-text/ +[VS Code](https://code.visualstudio.com/) is the recommended TypeScript IDE. +Follow [this guide](https://cmatskas.com/getting-started-with-typescript-and-sublime-text/) to set up Sublime Text. -**Now with documentation!** -The Max JS documentation has been included as JSDoc, with the permission of Cycling '74. +Now with documentation! +--- +The Max JS documentation has been included as JSDoc, with the permission of Cycling '74. -**Included in this archive** - /Definitions - cycling74-max7.d.ts Definition file for JavaScript in Max - cycling74-max7-jsui.d.ts Definition file for JSUI, MGraphics, Sketch, etc. - cycling74-max7-jitter.d.ts Definition file for using Jitter objects +Included in this archive +--- - /Modules + /TypeScript + tsconfig.json TypeScript configuration file + ExampleJS.ts Example [js] code + ExampleJSUI.ts Example [jsui] code ExampleModule.ts An example module used by both examples + /types + cycling74-max7.d.ts Definition file for JavaScript in Max + cycling74-max7-jsui.d.ts Definition file for JSUI, MGraphics, Sketch, etc. + cycling74-max7-jitter.d.ts Definition file for using Jitter objects - /ExampleJS + /JavaScript + ExampleJS.js JavaScript code generated from ExampleJS.ts + ExampleJSUI.js JavaScript code generated from ExampleJSUI.ts + ExampleModule.js JavaScript code generated from ExampleModule.ts ExampleJS.maxpat Example patcher - ExampleJS.ts Example [js] code - tsconfig.json TypeScript configuration file - - /ExampleJSUI ExampleJSUI.maxpat Example patcher - ExampleJSUI.ts Example [jsui] code - tsconfig.json TypeScript configuration file - /JavaScript - ExampleJS.js JavaScript code generated from ExampleJS.js and ExampleModule.ts - ExampleJS.js JavaScript code generated from ExampleJSUI.js and ExampleModule.ts -The TypeScript configuration files (tsconfig.json) are set up to merge each example into one JavaScript output file, this is the only way I have been able to get modules to work so far. Make sure compiled JavaScript files are in Max' search path. +Notes +--- + + * The TypeScript configuration file (`tsconfig.json`) is set up to output a separate .js file for each .ts file. + + * .ts files for scripts to be used in a [js] or [jsui] object must end in: + + let module = {}; + export = {}; + + This tricks tsc in outputting it as a separate module file, while still allowing Max to read it as a script. Do not do this in module files. + + * Make sure the compiled JavaScript files are in Max' search path, set this with `"outDir"` in your `tsconfig.json`. Make sure your TypeScript folder is not in a Max project directory or Max will mess up the file structure. -For more information on configuration files, look here: -https://www.typescriptlang.org/docs/handbook/tsconfig-json.html + * For continuous development run `tsc --watch` in the directory with your `tsconfig.json`. The .js files are then generated on save and Max will then reload automatically. + * For more information on configuration files, look [here](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html). -**Assigning properties to objects of type Global** +Assigning properties to objects of type Global +--- Cast to `````` to assign properties to objects of type ```Global``` like so: ``` diff --git a/ExampleJS/ExampleJS.ts b/TypeScript/ExampleJS.ts similarity index 69% rename from ExampleJS/ExampleJS.ts rename to TypeScript/ExampleJS.ts index 94bbb06..08cc840 100644 --- a/ExampleJS/ExampleJS.ts +++ b/TypeScript/ExampleJS.ts @@ -1,10 +1,9 @@ +import * as em from './ExampleModule' + inlets = 1; outlets = 1; autowatch = 1; -// Only works if ExampleModule.ts is declared before ExampleJS.ts in tsconfig.json! -let em = ExampleModule; - function bang() { let theObject = new em.TheClass(42); post("theObject.getIndex(): " + theObject.getIndex() + "\n"); @@ -17,12 +16,16 @@ function bang() { post("(g).newProperty: " + (g).newProperty + "\n"); } -function msg_float(v) +function msg_float(v: number) { outlet(0, em.square(v)); } -function msg_int(v) +function msg_int(v: number) { outlet(0, em.square(v)); -} \ No newline at end of file +} + +// .ts files with this at the end become a script usable in a [js] or [jsui] object +let module = {}; +export = {}; \ No newline at end of file diff --git a/ExampleJSUI/ExampleJSUI.ts b/TypeScript/ExampleJSUI.ts similarity index 75% rename from ExampleJSUI/ExampleJSUI.ts rename to TypeScript/ExampleJSUI.ts index 7bd92bb..b497b1b 100644 --- a/ExampleJSUI/ExampleJSUI.ts +++ b/TypeScript/ExampleJSUI.ts @@ -1,3 +1,5 @@ +import * as em from './ExampleModule' + inlets = 1; outlets = 1; autowatch = 1; @@ -7,8 +9,6 @@ m.init(); m.relative_coords = 0; m.autofill = 0; -// Only works if ExampleModule.ts is declared before ExampleJS.ts in tsconfig.json! -var em = ExampleModule; var t = 0; var a = 10.0; @@ -38,17 +38,21 @@ function bang() { m.redraw(); } -function setA(v){ +function setA(v: number){ a = v; m.redraw(); } -function setB(v){ +function setB(v: number){ b = v; m.redraw(); } -function setRes(v){ +function setRes(v: number){ div = Math.floor(v); m.redraw(); -} \ No newline at end of file +} + +// .ts files with this at the end become a script usable in a [js] or [jsui] object +let module = {}; +export = {}; \ No newline at end of file diff --git a/TypeScript/ExampleModule.ts b/TypeScript/ExampleModule.ts new file mode 100644 index 0000000..fc0b76f --- /dev/null +++ b/TypeScript/ExampleModule.ts @@ -0,0 +1,37 @@ + +// These two functions are painfully slow ;) +export function colorFn(x: number): number[] { + return [Math.sin(x) * 0.5 + 0.5, + Math.sin(x + 0.333 * Math.PI) * 0.5 + 0.5, + Math.sin(x + 0.666 * Math.PI) * 0.5 + 0.5, + 1.0]; +} + +export function pixelFn(x: number, y: number, t: number, prmA: number, prmB: number): number[] { + let r = Math.sin(t + x * 2.0) + Math.cos(t + y * 2.0); + r += Math.sin(t + x * Math.sin(t + x * 0.02) * prmA) + Math.cos(t + y * (Math.cos(t * 0.7) * 5.0)) * prmB; + return colorFn(r + t); +} + +export function square(x: number): number { + return x * x; +} + +export class TheClass { + + private index: number; + + constructor(index: number) { + this.index = index; + post("TheClass.constructor was called with the number parameter " + index + "\n"); + } + + getIndex(): number { + return this.index; + } + + post(): void { + post("TheClass: post!"); + post(); + } +} diff --git a/TypeScript/tsconfig.json b/TypeScript/tsconfig.json new file mode 100644 index 0000000..3a308fd --- /dev/null +++ b/TypeScript/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compileOnSave": true, + "compilerOptions": { + "module": "CommonJS", + "target": "es3", + "strict": true, + "noImplicitAny": true, + "allowUnreachableCode": true, + "sourceMap": false, + "lib": [ "es7" ], + "outDir": "../JavaScript/" + }, + "include": [ + "./*.ts", + "./types/*.d.ts" + ] +} \ No newline at end of file diff --git a/Definitions/cycling74-max7-jitter.d.ts b/TypeScript/types/cycling74-max7-jitter.d.ts similarity index 98% rename from Definitions/cycling74-max7-jitter.d.ts rename to TypeScript/types/cycling74-max7-jitter.d.ts index 89dd32b..0779323 100644 --- a/Definitions/cycling74-max7-jitter.d.ts +++ b/TypeScript/types/cycling74-max7-jitter.d.ts @@ -352,10 +352,10 @@ declare class JitterListener extends JitterObject { */ declare class JitterGUIUtils { static trackers: JitterGUITracker[]; - static add_client(dest, newclient): any; - static add_tracker(dest): any; - static delete_bogus_clients(dest): any; - static init(dest): any; + static add_client(dest: any, newclient: any): any; + static add_tracker(dest: any): any; + static delete_bogus_clients(dest: any): any; + static init(dest: any): any; } @@ -366,9 +366,9 @@ declare class JitterGUIUtils { */ declare class JitterGUITracker { constructor(dest: any); - add_client(newclient): any; + add_client(newclient: any): any; delete_bogus_clients(): any; - delete_duplicate_clients(newclient): any; + delete_duplicate_clients(newclient: any): any; make_listener(): any; } @@ -448,7 +448,7 @@ declare class JitterGUIElement { * parse jitter-style js arguments. * @param {any[]} ...args [description] */ - set_attr_args(...args: any[]); + set_attr_args(...args: any[]): void; /** * adding the unique_index property allows one js instance to own multiple JitterGUIElements diff --git a/Definitions/cycling74-max7-jsui.d.ts b/TypeScript/types/cycling74-max7-jsui.d.ts similarity index 98% rename from Definitions/cycling74-max7-jsui.d.ts rename to TypeScript/types/cycling74-max7-jsui.d.ts index 8db46e6..aa6183a 100644 --- a/Definitions/cycling74-max7-jsui.d.ts +++ b/TypeScript/types/cycling74-max7-jsui.d.ts @@ -646,7 +646,7 @@ declare class Sketch { * @param {number} delta_y [description] * @param {number} delta_z [description] */ - move(delta_x: number, delta_y: number, delta_z: number): void; + move(delta_x: number, delta_y: number, delta_z?: number): void; /** * Moves the drawing position to the location specified by the x, y, and z arguments. @@ -654,7 +654,7 @@ declare class Sketch { * @param {number} y [description] * @param {number} z [description] */ - moveto(x: number, y: number, z: number): void; + moveto(x: number, y: number, z?: number): void; /** * Draws a point at the location specified by the x, y, and z arguments. After this method has been called, the drawing position is updated to the location specified by the x, y, and z arguments. @@ -662,7 +662,7 @@ declare class Sketch { * @param {number} y [description] * @param {number} z [description] */ - point(x: number, y: number, z: number): void; + point(x: number, y: number, z?: number): void; /** * Draws a line from the current drawing position to the location specified the sum of the current drawing position and the delta x, y, and z arguments. After this method has been called, the drawing position is updated to the location specified by the sum of the current drawing position and the delta x, y, and z arguments. @@ -670,7 +670,7 @@ declare class Sketch { * @param {number} delta_y [description] * @param {number} delta_z [description] */ - line(delta_x: number, delta_y: number, delta_z: number): void; + line(delta_x: number, delta_y: number, delta_z?: number): void; /** * Draws a line from the current drawing position to the location specified by the x, y, and z arguments. After this method has been called, the drawing position is updated to the location specified by the x, y, and z arguments. @@ -678,7 +678,7 @@ declare class Sketch { * @param {number} y [description] * @param {number} z [description] */ - lineto(x: number, y: number, z: number): void; + lineto(x: number, y: number, z?: number): void; /** * Draws a line from the location specified by the x1, y1, and z1 arguments to the location specified by the x2, y2, and z2 arguments. After this method has been called, the drawing position is updated to the location specified by the x2, y2, and z2 arguments. @@ -690,6 +690,7 @@ declare class Sketch { * @param {number} z2 [description] */ linesegment(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number): void; + linesegment(x1: number, y1: number, x2: number, y2: number): void; /** * Draws a filled triangle with three corners specified by the x1, y1, z1, x2, y2, z2, x3, y3, and z3 arguments. After this method has been called, the drawing position is updated to the location specified by the x3, y3, and z3 arguments. @@ -704,7 +705,8 @@ declare class Sketch { * @param {number} z3 [description] */ tri(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number, x3: number, y3: number, z3: number): void; - + tri(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number): void; + /** * Draws a framed triangle with three corners specified by the x1, y1, z1, x2, y2, z2, x3, y3, and z3 arguments. After this method has been called, the drawing position is updated to the location specified by the x3, y3, and z3 arguments. * @param {number} x1 [description] @@ -767,7 +769,7 @@ declare class Sketch { * @param {number} scale_y [description] * @param {number} scale_z [description] */ - cube(scale_x: number, scale_y: number, scale_z: number): void; + cube(scale_x: number, scale_y: number, scale_z?: number): void; /** * Draws a cylinder with top radius specified by the radius1 argument, bottom radius specified by the radius2 argument, length specified by the mag argument, and center point at the current drawing position. If the theta_start and theta_end arguments are specified, then a patch will be drawn instead of a full cylinder. The theta_start and theta_end arguments are in terms of degrees(0-360). The current shapeorient, shapeslice, and shapeprim values will also affect the drawing. @@ -850,7 +852,7 @@ declare class Sketch { * @param {number} rotation_y [description] * @param {number} rotation_z [description] */ - shapeorient(rotation_x: number, rotation_y: number, rotation_z: number): void; + shapeorient(rotation_x: number, rotation_y: number, rotation_z?: number): void; /** * Sets the number of slices to use when rendering any of the "shape" drawing methods. Increasing the slice_a and slice_b arguments will increase the quality at which the shape is rendered, while decreasing these values will improve performance. @@ -956,7 +958,7 @@ declare class Sketch { * @param {number} z [description] * @return {number[]} [description] */ - worldtoscreen(x: number, y: number, z: number): number[]; + worldtoscreen(x: number, y: number, z?: number): number[]; /** * Begin definition of a stroked path of the style specified by the stroke_style argument. Currently supported stroke styles are "basic2d" and "line". @@ -982,7 +984,7 @@ declare class Sketch { * @param {number} y [description] * @param {number} z [description] */ - strokepoint(x: number, y: number, z: number): void; + strokepoint(x: number, y: number, z?: number): void; /** * The default2d method is a simple way to set the graphics state to default properties useful for 2D graphics. It is called everytime your object is resized if default2d() has been called more recently than default3d(). @@ -1032,7 +1034,7 @@ declare class Sketch { glmaterial(): void; glmatrixmode(mode: string): void; glmultmatrix(matrix_array: any[]): void; - glnormal(x: number, y: number, z: number): void; + glnormal(x: number, y: number, z?: number): void; glortho(left: number, right: number, bottom: number, top: number, near: number, far: number): void; glpointsize(size: number): void; glpolygonmode(): void; @@ -1042,19 +1044,20 @@ declare class Sketch { glpushattrib(): void; glpushmatrix(): void; glrect(x1: number, y1: number, x2: number, y2: number): void; - glrotate(angle: number, x: number, y: number, z: number): void; - glscale(x_scale: number, y_scale: number, z_scale: number): void; + glrotate(angle: number, x: number, y: number, z?: number): void; + glscale(x_scale: number, y_scale: number, z_scale?: number): void; glscissor(x: number, y: number, width: number, height: number): void; glshademodel(mode: any[]): void; gltexcoord(s: number[], t: number[]): void; gltexenv(parameter_name: string, val1: string, val2: string, val3: string, val4: string): void; gltexgen(coord: number[], parameter_name: string, val1: string, val2: string, val3: string, val4: string): void; gltexparameter(parameter_name: string, val1: string, val2: string, val3: string, val4: string): void; - gltranslate(delta_x: number, delta_y: number, delta_z: number): void; + gltranslate(delta_x: number, delta_y: number, delta_z?: number): void; glulookat(eye_x: number, eye_y: number, eye_z: number, center_x: number, center_y: number, center_z: number, up_x: number, up_y: number, up_z: number): void; + glulookat(eye_x: number, eye_y: number, center_x: number, center_y: number, up_x: number, up_y: number): void; gluortho2d(left: number, right: number, bottom: number, top: number): void; gluperspective(fovy: number, aspect: number, near: number, far: number): void; - glvertex(x: number, y: number, z: number): void; + glvertex(x: number, y: number, z?: number): void; glviewport(x: number, y: number, width: number, height: number): void; } @@ -1323,7 +1326,7 @@ declare class CanvasRenderingContext2D { lineTo(x: number, y: number): void; quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void; bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void; - arcTo(x1: number, y1: number, x2: number, y2: number, radius: number); + arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void; rect(x: number, y: number, w: number, h: number): void; arc(x: number, y: number, r: number, startAngle: number, endAngle: number, anticlockwise: number): void; fill(): void; @@ -1359,7 +1362,7 @@ declare class CanvasRenderingContext2D { declare class CanvasGradient { constructor(patternObj: Pattern, radiHelper: any); // TODO: radiHelper: any ? - addColorStop(offset: number, color: any); // TODO: color: any ? + addColorStop(offset: number, color: any): void; // TODO: color: any ? } diff --git a/Definitions/cycling74-max7.d.ts b/TypeScript/types/cycling74-max7.d.ts similarity index 99% rename from Definitions/cycling74-max7.d.ts rename to TypeScript/types/cycling74-max7.d.ts index 8dd58c7..dc05ea9 100644 --- a/Definitions/cycling74-max7.d.ts +++ b/TypeScript/types/cycling74-max7.d.ts @@ -13,7 +13,7 @@ declare var inlets: number; declare var outlets: number; declare var autowatch: number; declare var jsarguments: any[]; -declare var arguments: any[]; +declare var arguments: IArguments; declare var box: Maxobj; declare var editfontsize: number; declare var inlet: number; @@ -25,7 +25,7 @@ declare function error(message: any): void; declare function cpost(message?: any): void; declare function post(message?: any): void; declare function messnamed(object_name: string, message_name: string, message_arguments?: string): void; -declare function arrayfromargs(message: string, arguments: any[]): void; +declare function arrayfromargs(arguments: IArguments): any[]; declare function assist(arguments: any): void; declare function declareattribute(attribute_name: string, getter_name?: string, setter_name?: string, embed?: number): void; declare function embedmessage(method_name: string, ...arguments: any[]): void; @@ -1019,7 +1019,7 @@ declare class Max { * Similar to portabbrev, but offset is the channel offset added to identify input or output ports when a MIDI object can send to or receive from multiple ports by channel number. Must be a multiple of 16 (e.g. max midi portoffset innum PortA 16 sets the channel offset for PortA device to 16). * @param {any[]} ...message [description] */ - portoffset(...message: any[]); + portoffset(...message: any[]): void; /** * The word preempt, followed by a one (on) or zero (off), toggles Overdrive mode. @@ -1048,7 +1048,7 @@ declare class Max { * (Macintosh only) The word setrefreshrate, followed by a number, sets the rate, in frames per second, at which the visual display is updated. On Macintosh systems, the rate at which the screen is refreshed is unrelated to the rate at which you change its contents. Better visual performance can be achieved - at the cost of a slight performance decrease in Jitter, and little or no performance decrease for audio processing - by specifying a higher frame rate. When enabled using the enablerefresh 1 message, the default rate is 28.57 FPS. Refresh enable is off by default. * @param {number} fps [description] */ - refreshrate(fps: number); + refreshrate(fps: number): void; /** * The word runtime, followed by a zero or one and a message, executes the message if the current version of Max is a runtime version (1) or non-runtime (0).