Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Dante1349 committed Jan 24, 2022
1 parent b781122 commit b70d1ae
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const options: DeviceOptions = {
deviceNumber: 0 // Choose device from listMIDIDevices()
}

await MIDIPlugin.openDevice(options)
await MIDI.openDevice(options)


MIDIPlugin.addListener('MIDIEventReceived',
MIDI.addListener('MIDIEventReceived',
(message: MidiMessage) => console.log(message));

interface MidiMessage {
Expand Down
10 changes: 5 additions & 5 deletions example/src/app/home/home.page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ChangeDetectorRef, Component} from '@angular/core';
import {MidiMessage, DeviceOptions, MIDIPlugin} from 'capacitor-midi';
import {MidiMessage, DeviceOptions, MIDI} from 'capacitor-midi';

@Component({
selector: 'app-home',
Expand All @@ -12,19 +12,19 @@ export class HomePage {
opened = false;

constructor(private cd: ChangeDetectorRef) {
MIDIPlugin.listMIDIDevices()
MIDI.listMIDIDevices()
.then(devices => {
this.devices = devices.value;
});

MIDIPlugin.addListener('MIDIEventReceived', (message: MidiMessage) => {
MIDI.addListener('MIDIEventReceived', (message: MidiMessage) => {
this.messages.push(message);
cd.detectChanges();
});
}

updateDevices(): void {
MIDIPlugin.listMIDIDevices()
MIDI.listMIDIDevices()
.then(devices => {
this.devices = devices.value;
});
Expand All @@ -34,7 +34,7 @@ export class HomePage {
const deviceOptions: DeviceOptions = {
deviceNumber: deviceNumber
};
MIDIPlugin.openDevice(deviceOptions).then(r => {
MIDI.openDevice(deviceOptions).then(r => {
this.clearMessages();
});
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "capacitor-midi",
"version": "0.0.3",
"version": "0.0.4",
"description": "Grants access to midi devices via native libraries or WebMIDI.",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -38,7 +38,7 @@
"eslint": "eslint . --ext ts",
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
"swiftlint": "node-swiftlint",
"docgen": "docgen --api MIDIPluginPlugin --output-readme README.md --output-json dist/docs.json",
"docgen": "docgen --api MIDIPlugin --output-readme README.md --output-json dist/docs.json",
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
"clean": "rimraf ./dist",
"watch": "tsc --watch",
Expand Down
2 changes: 1 addition & 1 deletion src/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {ListenerCallback, PluginListenerHandle} from "@capacitor/core";

export interface MIDIPluginPlugin{
export interface MIDIPlugin {
listMIDIDevices(): Promise<{ value: string[] }>

openDevice(options: DeviceOptions): Promise<void>
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { registerPlugin } from '@capacitor/core';

import type { MIDIPluginPlugin } from './definitions';
import type { MIDIPlugin } from './definitions';

const MIDIPlugin = registerPlugin<MIDIPluginPlugin>('MIDIPlugin', {
const MIDI = registerPlugin<MIDIPlugin>('MIDIPlugin', {
web: () => import('./web').then(m => new m.MIDIPluginWeb()),
});

export * from './definitions';
export { MIDIPlugin };
export { MIDI };
4 changes: 2 additions & 2 deletions src/web.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {WebPlugin} from '@capacitor/core';

import {WebMIDIHandler} from "./WebMIDIHandler";
import type {DeviceOptions, MIDIPluginPlugin} from './definitions';
import type {DeviceOptions, MIDIPlugin} from './definitions';

export class MIDIPluginWeb extends WebPlugin implements MIDIPluginPlugin {
export class MIDIPluginWeb extends WebPlugin implements MIDIPlugin {
async listMIDIDevices(): Promise<{ value: string[] }> {
const wmh = WebMIDIHandler.instance;
await wmh.initWebMidi()
Expand Down

0 comments on commit b70d1ae

Please sign in to comment.