npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

evseq

v0.0.5

Published

A sequencer useful for controlling audio, lighting, and anything else that needs to be played, paused, stopped and/or resumed.

Downloads

4

Readme

Build Status Code Coverage

evseq

A simple event sequencer for Node.js.

EvSeq is useful for controlling audio, lighting, and anything else that needs to be played, paused, stopped and/or resumed. It is especially well suited for use with RxJS.

Hello world

var EvSeq = require("evseq");
var ril = EvSeq.rerouteIfLate('foo', 'ignore');
var Rx = require('rx');
var Observable = Rx.Observable;
var EventEmitter = require('events').EventEmitter;
var P = require('bluebird').Promise;
var e = new EventEmitter();
var sum = 0;
var seq = new EvSeq(e).at('0s', ril, 1)
  .at('1.5s', ril, 1)
  .at('3.1s', ril, 1, 'aGroupName')
  .at('4.5s', ril, 1, 'aGroupName')
  .at('5.8s', ril, 1);
var subscription = Observable.fromEvent(e, 'foo')
  .subscribe((x) => sum += x);

P.resolve(seq.play()).
  delay(2000).
  then(()=>{
    console.log(sum); // 2
    seq.stop(); // stop rewinds to beginning
    sum=0; // rest to 0
    return P.resolve(seq.play())
  }).
  delay(2000).
  then(()=>P.resolve(seq.pause())).
  delay(2000).
  then(()=>{
    console.log(sum); // pause works, will be 2
    return P.resolve(seq.play());
  }).
  delay(2000).
  then(()=>P.resolve(seq.softpause())).
  delay(2000).
  then(()=>{
    // softpause allows pending members of a group to be emitted
    console.log(sum); // will be 4 because of softpause
    return P.resolve(seq.stop());
  });

API

constructor

var myEvSeq = new EvSeq(e: EventEmitter, xtra ?: any)

Create a EvSeq object that emits events from e, passing xtra to a calling function at the time of emission.

at

myEvSeq.at(t: string,
    key: string | (x: number, y: any) => void,
    val: mixed | (x: number, y: any) => void,
    group ? : string): EvSeq

Schedules an event at time t. Time t can be expressed in seconds, milliseconds, microseconds or nanoseconds. It uses the same format of timing as nanotimer.

Key key and value value can be either literals or functions.

  • If they are literals, the are emitted in the traditional sense from the event passed into the EvSeq constructor, ie: e.emit(key, value).
  • If they are functions, then the return value of the functions are used for the key and value to the emitter. The function takes two parameters: the first is the error (meaning how late the emission happens compared to the request) and the second are the extra arguments passed to the EvSeq constructor. See Functions passed as arguments to at.

play

myEvSeq.play(): void

Plays a seequence, picking up from the point at which it was paused or to which it was seeked, otherwise starts from 0s.

pause

myEvSeq.pause(): void

Pauses a sequence. pause differs from stop in that pause does not set the timeline to 0s.

stop

myEvSeq.stop(): void

Stops a sequence. stop differs from pause in that stop sets the timeline to 0s.

seek

myEvSeq.seek(t: string): void

Fastforwards a sequence to time t. This does not interrupt playing if a sequence is currently playing.

softpause

myEvSeq.softpause(): void

Like pause, except events in the event's group will execute after the pause. For example, in:

var e = new EventEmitter();
var seq = new EvSeq(e).at('0s', 'foo', 1)
  .at('2.1s', 'foo', 1)
  .at('3.1s', 'foo', 1, 'aGroupName')
  .at('4.5s', 'foo', 1, 'aGroupName')
  .at('5.8s', 'foo', 1);

If softpause is called between 3.1 and 4.5 seconds, the event at 4.5s will be emitted.

print

myEvSeq.print(): void

Prints information about the sequence to the console.

rerouteIfLate

EvSeq.rerouteIfLate(ifOnTime: any, ifLate: any): (i: number) => any

Convenience static method for rerouting an event if it is late (meaning if it has positive error for its time value - see (Functions passed as arguments to at. The value at ifOnTime is returned if the function is ontime, otherwise ifLate is returned. For example:

mySequence.at('10s', EvSeq.rerouteIfLate('eventICareAbout', 'trashbin'), 1)

Functions passed as arguments to at

As stated above, a function passed to at for the key or value is in the form:

function(i: number, x: any)

Where i is the error in time and x is whateve extra value is passed into the EvSeq constructor. The error parameter is perhaps the most important thing to understand about EvSeq and is where its power lies. If a sequence is paused after 3 seconds and then resumed, any event that happens before the 3 second mark is called again with the difference in time as the first argument. For example, an event scheduled to be emitted at 0.5s will be called with an error of 2.5 if the pause happened at 3 seconds. This allows audio files, lighting cues, whatever to pick up where they left off after pausing. A utility function, rerouteIfLate, helps ignore events that happen before a particular timestamp.