diff --git a/src/API.ts b/src/API.ts index 33f00eb..1f57475 100644 --- a/src/API.ts +++ b/src/API.ts @@ -4,8 +4,8 @@ import { tryEvaluate } from "./Evaluator"; import { DrunkWalk } from "./Utils/Drunk"; import { scale } from "./Scales"; import { Editor } from "./main"; -import { Sound } from "./classes/Sound"; -import { Note } from "./classes/Note"; +import { SoundEvent } from "./classes/SoundEvent"; +import { NoteEvent } from "./classes/MidiEvent"; import { LRUCache } from "lru-cache"; import { Player } from "./classes/ZPlayer"; import { @@ -236,7 +236,7 @@ export class UserAPI { } }; - public note = (value: number = 60): Note => { + public midi = (value: number|object = 60): NoteEvent => { /** * Sends a MIDI note to the current MIDI output. * @@ -244,7 +244,7 @@ export class UserAPI { * @param options - an object containing options for that note * { channel: 0, velocity: 100, duration: 0.5 } */ - return new Note(value, this.app); + return new NoteEvent(value, this.app); }; public sysex = (data: Array): void => { @@ -1234,9 +1234,10 @@ export class UserAPI { // Trivial functions // ============================================================= - sound = (sound: string) => { - return new Sound(sound, this.app); + sound = (sound: string|object) => { + return new SoundEvent(sound, this.app); }; + snd = this.sound; samples = samples; soundMap = soundMap; diff --git a/src/Documentation.ts b/src/Documentation.ts index 452081b..f3f8a29 100644 --- a/src/Documentation.ts +++ b/src/Documentation.ts @@ -35,11 +35,11 @@ Press ${key_shortcut(

 bpm(80)
 mod(0.25) :: sound('sawtooth')
-  .note(seqbar(
+  .midi(seqbar(
     pick(60, 67, 63) - 12,  pick(60, 67, 63) - 12, 
     pick(60, 67, 63) - 12 + 5, pick(60, 67, 63) - 12 + 5,
     pick(60, 67, 63) - 12 + 7, pick(60, 67, 63) - 12 + 7) + (sometimes() ? 24 : 12))
-  .dur(0.1).fmi(8).fmh(4).room(0.9)
+  .sustain(0.1).fmi(8).fmh(4).room(0.9)
   .gain(0.75).cutoff(500 + usine(8) * 10000)
   .delay(0.5).delaytime(bpm() / 60 / 4 / 3)
   .delayfeedback(0.25)
@@ -192,27 +192,25 @@ const midi: string = `
 
 You can use Topos to play MIDI thanks to the [WebMIDI API](https://developer.mozilla.org/en-US/docs/Web/API/Web_MIDI_API). You can currently send notes, control change, program change and so on. You can also send a MIDI Clock to your MIDI devices or favorite DAW. Note that Topos is also capable of playing MIDI using **Ziffers** which provides a better syntax for melodic expression.
 
-
-
 ## Notes
-- note(note: number, options: {}): send a MIDI Note. This function can take an object as a second argument to specify the MIDI channel, velocity, etc... (_e.g._ note(60, {channel: 1, velocity: 127})).
+- midi(note: number|object): send a MIDI Note. Object can take parameters {note: number, channel: number, port: number|string, velocity: number}.
 
 \`\`\`javascript
     bpm(80) // Setting a default BPM
-    mod(.5) && note(36 + seqbeat(0,12)).duration(0.02).out()
-    mod(.25) && note(pick(64, 76)).duration(0.05).out()
-    mod(.75) && note(seqbeat(64, 67, 69)).duration(0.05).out()
-    sometimes() && mod(.25) && note(seqbeat(64, 67, 69) + 24).duration(0.05).out()
+    mod(.5) && midi(36 + seqbeat(0,12)).sustain(0.02).out()
+    mod(.25) && midi(pick(64, 76)).sustain(0.05).out()
+    mod(.75) && midi(seqbeat(64, 67, 69)).sustain(0.05).out()
+    sometimes() && mod(.25) && midi(seqbeat(64, 67, 69) + 24).sustain(0.05).out()
 \`\`\`
 
 ## Note chaining
 
-The note(number) function can be chained to _specify_ a midi note more. For instance, you can add a duration, a velocity, a channel, etc...:
+The midi(number|object) function can be chained to _specify_ a midi note more. For instance, you can add a duration, a velocity, a channel, etc... by chaining:
 
 \`\`\`javascript
-mod(0.25) && note(60)
+mod(0.25) && midi(60)
   .sometimes(n=>n.note(irand(40,60)))
-  .duration(0.05)
+  .sustain(0.05)
   .channel(2)
   .port("bespoke")
   .out()
diff --git a/src/classes/Event.ts b/src/classes/AbstractEvents.ts
similarity index 79%
rename from src/classes/Event.ts
rename to src/classes/AbstractEvents.ts
index 9ff1636..2ef0ac4 100644
--- a/src/classes/Event.ts
+++ b/src/classes/AbstractEvents.ts
@@ -75,7 +75,7 @@ export abstract class Event {
 
 }
 
-export abstract class SoundEvent extends Event {
+export abstract class AudibleEvent extends Event {
     constructor(app: Editor) {
         super(app);
     }
@@ -119,33 +119,4 @@ export abstract class SoundEvent extends Event {
         // Overwrite in subclasses
     }
 
-}
-
-export class Skip {
-
-    _fallbackMethod = (): Skip => {
-        return this;
-    }
-  
-    public static createRestProxy = () => {
-        const instance = new Skip();
-        return new Proxy(instance, {
-            // @ts-ignore
-            get(target, propKey, receiver) {
-                // @ts-ignore
-                if (typeof target[propKey] === 'undefined') {
-                  return target._fallbackMethod;
-                }
-                // @ts-ignore
-                return target[propKey];
-              },
-              // @ts-ignore
-              set(target, propKey, value, receiver) {
-                return false;
-              }
-          });
-    }
-
-    out = (): void => {}
-
-  }
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/classes/Note.ts b/src/classes/MidiEvent.ts
similarity index 96%
rename from src/classes/Note.ts
rename to src/classes/MidiEvent.ts
index eed2025..6fdfa15 100644
--- a/src/classes/Note.ts
+++ b/src/classes/MidiEvent.ts
@@ -1,9 +1,9 @@
-import { SoundEvent } from './Event';
+import { AudibleEvent } from './AbstractEvents';
 import { type Editor } from '../main';
 import { MidiConnection } from "../IO/MidiConnection";
 import { midiToFreq, noteFromPc } from 'zifferjs';
 
-export class Note extends SoundEvent {
+export class NoteEvent extends AudibleEvent {
     midiConnection: MidiConnection;
 
     constructor(input: number|object, public app: Editor) {
diff --git a/src/classes/Rest.ts b/src/classes/RestEvent.ts
similarity index 85%
rename from src/classes/Rest.ts
rename to src/classes/RestEvent.ts
index 649e989..05bb398 100644
--- a/src/classes/Rest.ts
+++ b/src/classes/RestEvent.ts
@@ -1,7 +1,7 @@
 import { type Editor } from '../main';
-import { Event } from "./Event";
+import { Event } from "./AbstractEvents";
 
-export class Rest extends Event {
+export class RestEvent extends Event {
     constructor(duration: number, app: Editor) {
         super(app);
         this.values["duration"] = duration;
@@ -12,7 +12,7 @@ export class Rest extends Event {
     }
 
     public static createRestProxy = (duration: number, app: Editor) => {
-        const instance = new Rest(duration, app);
+        const instance = new RestEvent(duration, app);
         return new Proxy(instance, {
             // @ts-ignore
             get(target, propKey, receiver) {
diff --git a/src/classes/SkipEvent.ts b/src/classes/SkipEvent.ts
new file mode 100644
index 0000000..1f83996
--- /dev/null
+++ b/src/classes/SkipEvent.ts
@@ -0,0 +1,28 @@
+export class SkipEvent {
+
+    _fallbackMethod = (): SkipEvent => {
+        return this;
+    }
+  
+    public static createSkipProxy = () => {
+        const instance = new SkipEvent();
+        return new Proxy(instance, {
+            // @ts-ignore
+            get(target, propKey, receiver) {
+                // @ts-ignore
+                if (typeof target[propKey] === 'undefined') {
+                  return target._fallbackMethod;
+                }
+                // @ts-ignore
+                return target[propKey];
+              },
+              // @ts-ignore
+              set(target, propKey, value, receiver) {
+                return false;
+              }
+          });
+    }
+
+    out = (): void => {}
+
+  }
\ No newline at end of file
diff --git a/src/classes/Sound.ts b/src/classes/SoundEvent.ts
similarity index 98%
rename from src/classes/Sound.ts
rename to src/classes/SoundEvent.ts
index 889bcfc..ba9346d 100644
--- a/src/classes/Sound.ts
+++ b/src/classes/SoundEvent.ts
@@ -1,5 +1,5 @@
 import { type Editor } from '../main';
-import { SoundEvent } from './Event';
+import { AudibleEvent } from './AbstractEvents';
 import { midiToFreq, noteFromPc } from 'zifferjs';
 
 import {
@@ -7,7 +7,7 @@ import {
   // @ts-ignore
 } from "superdough";
 
-export class Sound extends SoundEvent {
+export class SoundEvent extends AudibleEvent {
 
     constructor(sound: string|object, public app: Editor) {
         super(app);
diff --git a/src/classes/ZPlayer.ts b/src/classes/ZPlayer.ts
index a5f2ce7..c22c773 100644
--- a/src/classes/ZPlayer.ts
+++ b/src/classes/ZPlayer.ts
@@ -1,9 +1,10 @@
 import { Chord, Pitch, Rest as ZRest, Ziffers } from "zifferjs";
 import { Editor } from "../main";
-import { Event, Skip } from "./Event";
-import { Sound } from "./Sound";
-import { Note } from "./Note";
-import { Rest } from "./Rest";
+import { Event } from "./AbstractEvents";
+import { SkipEvent } from "./SkipEvent";
+import { SoundEvent } from "./SoundEvent";
+import { NoteEvent } from "./MidiEvent";
+import { RestEvent } from "./RestEvent";
 
 export class Player extends Event {
     input: string;
@@ -40,30 +41,28 @@ export class Player extends Event {
         if(this.areWeThereYet()) {
             const event = this.next() as Pitch|Chord|ZRest;
             if(event instanceof Pitch) {
-                // TODO: Quick hack. Select which attributes to use, but some ziffers stuff is needed for chaining key change etc.
                 const obj = event.getExisting("freq","pitch","key","scale","octave");
-                return new Sound(obj, this.app).sound(name);
+                return new SoundEvent(obj, this.app).sound(name);
             } else if(event instanceof ZRest) {
-                return Rest.createRestProxy(event.duration, this.app);
+                return RestEvent.createRestProxy(event.duration, this.app);
             } 
         } else {
-            return Skip.createRestProxy();
+            return SkipEvent.createSkipProxy();
         }
     }
 
-    note(value: number|undefined = undefined) {
+    midi(value: number|undefined = undefined) {
          if(this.areWeThereYet()) {
             const event = this.next() as Pitch|Chord|ZRest;
             if(event instanceof Pitch) {
-                  // TODO: Quick hack. Select which attributes to use, but some ziffers stuff is needed for chaining key change etc.
                 const obj = event.getExisting("note","pitch","bend","key","scale","octave");
-                const note = new Note(obj, this.app);
+                const note = new NoteEvent(obj, this.app);
                 return value ? note.note(value) : note;
             } else if(event instanceof ZRest) {
-                return Rest.createRestProxy(event.duration, this.app);
+                return RestEvent.createRestProxy(event.duration, this.app);
             } 
         } else {
-            return Skip.createRestProxy();
+            return SkipEvent.createSkipProxy();
         }
     }