Skip to content

Commit

Permalink
Merge pull request #28 from CorvusPrudens/dev
Browse files Browse the repository at this point in the history
Added MIDI package
  • Loading branch information
CorvusPrudens authored Sep 30, 2023
2 parents da64f4e + 6c8470f commit 4d8e846
Show file tree
Hide file tree
Showing 11 changed files with 643 additions and 414 deletions.
1 change: 1 addition & 0 deletions examples/USB_MIDI.bell

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="noindex">
<title>Daisy Bell</title>
<script>
document.location.href = "./dist/"
Expand Down
48 changes: 44 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jspatcher/jspatcher",
"version": "0.3.4",
"version": "0.3.5",
"description": "patcher js",
"scripts": {
"prebuild": "node ./src/scripts/patchSemanticUICss.js",
Expand All @@ -25,6 +25,7 @@
"@electrosmith/package-math": "file:../objects/math/web",
"@electrosmith/package-ui": "file:../objects/ui/web",
"@electrosmith/package-utilities": "file:../objects/utilities/web",
"@electrosmith/package-midi": "file:../objects/midi/web",
"@ffmpeg/core": "^0.10.0",
"@ffmpeg/ffmpeg": "^0.10.1",
"@grame/libmusicxml": "^3.19.1",
Expand Down
3 changes: 3 additions & 0 deletions src/components/topmenu/FileMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ import AtariPunkConsole from "../../../examples/AtariV2.bell";
import RandomNoteGenerator from "../../../examples/RandomNoteGenerator.bell";
import SawSynthBp from "../../../examples/SawSynthBp.bell";
import Seed2DFMRect from "../../../examples/s2dfm_simple.bell";
import UsbMidi from "../../../examples/USB_MIDI.bell";


const examples: Record<string, any> = {
"8 Step Sequencer": [EightStepSequencer, ""],
"Atari Punk Console": [AtariPunkConsole, ""],
"Blink": [BlinkExample, "Seed"],
"USB MIDI": [UsbMidi, "Seed"],
"Simple Rect": [Seed2DFMRect, "S2DFM Eval Euro"],
"Random Note Generator": [RandomNoteGenerator, ""],
"Saw Synth BP": [SawSynthBp, ""],
Expand Down
4 changes: 2 additions & 2 deletions src/components/topmenu/FlashMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ export default class FlashMenu extends React.PureComponent<P, S> {
</Dropdown>
</div>
{/* {this.state.device !== null ? <div className="monitor">Connected to {this.state.device.device_.productName}</div> : <div></div>} */}
{this.state.building && this.state.progress === null ? <div style={loaderDivStyle}><Loader active inline size="mini"></Loader></div> : <div></div>}
{this.state.building && this.state.progress !== null ? <div style={{ ...loaderDivStyle, width: '250px', alignSelf: 'center', marginBottom: '0' }}><Progress size="small" inverted active percent={this.state.progress} progress='percent'></Progress></div> : <div></div>
{this.state.building && this.state.progress === null ? <div style={loaderDivStyle}><Loader inverted active inline size="mini"></Loader></div> : <div></div>}
{this.state.building && this.state.progress !== null ? <div style={{ ...loaderDivStyle, width: '250px', alignSelf: 'center', marginBottom: '0' }}><Progress size="small" active percent={this.state.progress} progress='percent'></Progress></div> : <div></div>
}
{this.state.building ? <div className="monitor">{this.state.build_message}</div> : <div></div>}
{this.state.build_error ? <div className="monitor"> {this.state.error_message} </div> : <div></div>}
Expand Down
125 changes: 77 additions & 48 deletions src/core/hardware/Compatibility.ts
Original file line number Diff line number Diff line change
@@ -1,74 +1,103 @@

import { BasePin } from "./types";
import { BasePin, USBBus } from "./types";

export function compatibleBus(pins: BasePin[]) {
// idk they're all complicated and I don't know what they mean
return false;
// USB Compatibility Check
let dplusCount = 0;
let dminusCount = 0;
let idCount = 0;

pins.forEach((pin) => {
if (pin.busCapabilities) {
for (const busType in pin.busCapabilities) {
const bus = pin.busCapabilities[busType] as USBBus;
if (bus.usb) {
// Increment counters based on USB capabilities
if (bus.dplus) dplusCount++;
if (bus.dminus) dminusCount++;
if (bus.id) idCount++;
}
}
}
});

// Let's consider tie flexibility
const tiePinsCount = pins.filter((p) => p.tie).length;

if (
pins.length === 2 &&
(dplusCount === 1 || dminusCount === 1 || idCount === 1) &&
tiePinsCount === 1
) {
// If there's only one dplus, dminus, or id, the tie pin can accommodate it
return true;
}

if (dplusCount >= 2 || dminusCount >= 2) {
return true;
}

// Continue with other bus checks (SPI, I2C, etc.) here when you want to expand compatibility checks.
return false;
}

export function compatibleDigital(pins: BasePin[]) {
let num_outputs = pins.filter(p => p.digitalOutput && !p.digitalInput).length;
let num_outputs = pins.filter((p) => p.digitalOutput && !p.digitalInput).length;

if (num_outputs > 1) {
return false;
}
if (num_outputs > 1) {
return false;
}

// now, for all fixed outputs, every other pin must have an input
let outputs = pins.map((p, i) => ({ p, i })).filter(({ p }) => p.digitalOutput);
// now, for all fixed outputs, every other pin must have an input
let outputs = pins.map((p, i) => ({ p, i })).filter(({ p }) => p.digitalOutput);

let some_valid_config = false;
for (const output of outputs) {
const { p: pin, i: index } = output;
let some_valid_config = false;
for (const output of outputs) {
const { p: pin, i: index } = output;

// In any configuration where an output is able to not conflict, there must be a compatibility
if (pins.filter((_, i) => i !== index).every(p => p.digitalInput || p.tie)) {
some_valid_config = true;
break;
}
// In any configuration where an output is able to not conflict, there must be a compatibility
if (pins.filter((_, i) => i !== index).every((p) => p.digitalInput || p.tie)) {
some_valid_config = true;
break;
}
}

// otherwise, simple analog connections should be compatible
return some_valid_config;
// otherwise, simple analog connections should be compatible
return some_valid_config;
}

export function compatibleAnalog(pins: BasePin[]) {
let num_outputs = pins.filter(p => p.analogOutput && !p.analogInput).length;
let num_outputs = pins.filter((p) => p.analogOutput && !p.analogInput).length;

if (num_outputs > 1) {
return false;
}
if (num_outputs > 1) {
return false;
}

// now, for all outputs, every other pin must have an input
let outputs = pins.map((p, i) => ({ p, i })).filter(({ p }) => p.analogOutput);
// now, for all outputs, every other pin must have an input
let outputs = pins.map((p, i) => ({ p, i })).filter(({ p }) => p.analogOutput);

let some_valid_config = false;
for (const output of outputs) {
const { p: pin, i: index } = output;
let some_valid_config = false;
for (const output of outputs) {
const { p: pin, i: index } = output;

// In any configuration where an output is able to not conflict, there must be a compatibility
if (pins.filter((_, i) => i !== index).every(p => p.analogInput || p.tie)) {
some_valid_config = true;
break;
}
// In any configuration where an output is able to not conflict, there must be a compatibility
if (pins.filter((_, i) => i !== index).every((p) => p.analogInput || p.tie)) {
some_valid_config = true;
break;
}
}

// otherwise, simple analog connections should be compatible
return some_valid_config;
// otherwise, simple analog connections should be compatible
return some_valid_config;
}

export function compatiblePins(pins: BasePin[]) {
let compatibilities = [compatibleBus, compatibleDigital, compatibleAnalog];

let compatibilities = [
compatibleBus,
compatibleDigital,
compatibleAnalog,
];
// If any of the compatibilities are true, then the pins are compatible
// TODO -- this should probably return exactly which aspects are compatible
if (compatibilities.some((f) => f(pins))) {
return true;
}

// If any of the compatibilities are true, then the pins are compatible
// TODO -- this should probably return exactly which aspects are compatible
if (compatibilities.some(f => f(pins))) {
return true;
}

return false;
return false;
}
14 changes: 8 additions & 6 deletions src/core/hardware/objects/hardware/HardwareObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import Gpo from "./Gpo";
import AMux from "./Mux";
import Button from "./Button";
import Cv from "./Cv";
import UsbMidi from "./UsbMidi";

export default {
'knob': Knob,
'gpi': Gpi,
'gpo': Gpo,
'amux': AMux,
'button': Button,
'cv': Cv,
knob: Knob,
gpi: Gpi,
gpo: Gpo,
amux: AMux,
button: Button,
cv: Cv,
usbmidi: UsbMidi,
};
Loading

0 comments on commit 4d8e846

Please sign in to comment.