Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cycle-midi

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cycle-midi

Cycle drivers to control real instruments with WebMIDI

  • 0.1.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

cycle-midi

Cycle.js drivers to send and receive notes using Web MIDI.

Drivers

  • connectionDriver
  • instrumentDriver

connectionDriver

connectionDriver accepts a stream. Whenever that stream dispatches, it tries to connect to the instrument over Web MIDI. It returns a stream that dispatches true when the connection attempt succeeds and false when it fails.

instrumentDriver

instrumentDriver accepts a stream of notes to send to the instrument. It may eventually return a stream of notes played on the instrument, but it doesn't do that yet.

Example

function Background({ messages: message$, instrumentConnection: instrumentAvailability$ }) {
  const connectionRequest$ = message$.filter(
    message => message.type === 'connect_to_instrument'
  );

  const playRandomNote$ = message$.filter(
    message => message.type === 'play_random_note'
  );

  return {
    instrumentConnection: connectionRequest$,
    instrument: playRandomNote$.map(
      () => (
        {
          // the MIDI ID of the note, from 21 for A0 to 108 for C8
          note,

          // number of milliseconds to play a note for
          duration: 150,

          // 1 is very soft; 128 is very hard
          velocity: Math.random() * 128,

          // number of milliseconds since the instrument connection to wait
          // before playing this note
          time: 0,
        }
      )
    ),
    messages: instrumentAvailability$.map(
      isAvailable => (
        {
          type: 'instrument_availability_changed',
          payload: true,
        }
      )
    ),
  }
}

To see an real extension written with these drivers, check out the midicast source code.

Installation

yarn add cycle-midi

Usage

Because the two drivers share a single connection to the instrument, you must instantiate them together with makeInstrumentAndConnectionDriver():

import {
  makeInstrumentAndConnectionDriver,
} from 'cycle-midi';

const {
  instrumentDriver,
  connectionDriver,
} = makeInstrumentAndConnectionDriver();

run(
  Background,
  {
    instrument: instrumentDriver,
    instrumentConnection: connectionDriver,
  }
);

License

Apache 2.0

Keywords

FAQs

Package last updated on 04 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc