Skip to content

Commit

Permalink
File restructuring and wiki updates
Browse files Browse the repository at this point in the history
- because "midi_player" sounds lame!!!!
  • Loading branch information
spessasus committed Aug 9, 2023
1 parent 506da38 commit a2e3b64
Show file tree
Hide file tree
Showing 38 changed files with 110 additions and 104 deletions.
18 changes: 9 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SpessaSynth</title>
<link rel="stylesheet" href="src/css/style.css">
<link rel="stylesheet" href="src/css/sequencer_ui.css">
<link rel="stylesheet" href="src/css/keyboard_ui.css">
<link rel="stylesheet" href="src/css/synthesizer_ui.css">
<link rel="stylesheet" href="src/css/keyboard.css">
<link rel="stylesheet" href='src/website/css/style.css'>
<link rel="stylesheet" href='src/website/css/sequencer_ui.css'>
<link rel="stylesheet" href='src/website/css/keyboard_ui.css'>
<link rel="stylesheet" href='src/website/css/synthesizer_ui.css'>
<link rel="stylesheet" href='src/website/css/keyboard.css'>

<style>
a{
Expand Down Expand Up @@ -57,11 +57,11 @@ <h2 id="text_event"></h2>
<script type="module">
"use strict"

import {Manager} from "./src/js/website/manager.js";
import {MIDI} from "./src/js/midi_parser/midi_loader.js";
import {Manager} from "./src/website/manager.js";
import {MIDI} from "./src/spessasynth_lib/midi_parser/midi_loader.js";

import {SoundFont2} from "./src/js/soundfont/soundfont_parser.js";
import {ShiftableByteArray} from "./src/js/utils/shiftable_array.js";
import {SoundFont2} from "./src/spessasynth_lib/soundfont/soundfont_parser.js";
import {ShiftableByteArray} from "./src/spessasynth_lib/utils/shiftable_array.js";


const TITLE = "SpessaSynth: SoundFont2 Javascript Synthetizer Online Demo";
Expand Down
11 changes: 11 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import open from "open";
import express from "express";
import fs from "fs";
import path from 'path';
import {fileURLToPath} from 'url';

const app = express();
const PORT = 81;
const HOST = "localhost";
5
// 👇️ "/home/borislav/Desktop/javascript/index.js"
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);


app.use(express.static("src"));
app.use(express.static("soundfonts"));

fs.writeFile("config.json", "{}", {flag: "wx"}, () => {});

app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, "src", "website", "index.html"));
})

app.get("/soundfonts", (req, res) => {
const fileNames = fs.readdirSync("soundfonts").filter(fName => fName.slice(-3).toLowerCase() === "sf2");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,36 +144,45 @@ export class MIDI{
if(statusByte === messageTypes.marker)
{
const text = readBytesAsString(eventData, eventData.length).trim().toLowerCase();
if(text === "start")
switch (text)
{
loopStart = totalTicks;
default:
break;

case "start":
case "loopstart":
loopStart = totalTicks;
break;

case "loopend":
loopEnd = totalTicks;
}
console.log(text);
eventData.currentIndex = 0;

}
else
// check for loop (CC 2/4)
if((statusByte & 0xF0) === messageTypes.controllerChange)
{
// loop start
if(eventData[0] === 2)
switch(eventData[0])
{
loopStart = totalTicks;
}

// loop end
if(eventData[0] === 4)
{
if(loopEnd === null)
{
loopEnd = totalTicks;
}
else
{
// this controller has occured more than once, this means that it doesnt indicate the loop
loopEnd = 0;
}
case 2:
case 116:
loopStart = totalTicks;
break;

case 4:
case 117:
if(loopEnd === null)
{
loopEnd = totalTicks;
}
else
{
// this controller has occured more than once, this means that it doesnt indicate the loop
loopEnd = 0;
}
break;
}
}
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {MIDI} from "../../midi_parser/midi_loader.js";
import {MIDI} from "../midi_parser/midi_loader.js";
import {Synthetizer} from "../synthetizer/synthetizer.js";
import {Renderer} from "../../ui/renderer.js";
import {getEvent, messageTypes, midiControllers, MidiMessage} from "../../midi_parser/midi_message.js";
import {formatTime} from "../../utils/other.js";
import {readBytesAsUintBigEndian} from "../../utils/byte_functions.js";
import {Renderer} from "../../website/ui/renderer.js";
import {getEvent, messageTypes, midiControllers, MidiMessage} from "../midi_parser/midi_message.js";
import {formatTime} from "../utils/other.js";
import {readBytesAsUintBigEndian} from "../utils/byte_functions.js";

export class Sequencer {
/**
Expand Down Expand Up @@ -466,10 +466,6 @@ export class Sequencer {

case messageTypes.noteOn:
const velocity = event.messageData[1];
if(this.synth.highPerformanceMode && this.synth.voicesAmount > this.synth.voiceCap * 0.7 && velocity < 30)
{
return;
}
if(velocity > 0) {
this.synth.noteOn(statusByteData.channel, event.messageData[0], velocity);
this.playingNotes.push({
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ export class Sample{
{
if(!this.buffer)
{
this.buffer = context.createBuffer(1, this.sampleData.length, this.sampleRate);
this.buffer.getChannelData(0).set(this.getAudioData());
throw "AudioBuffer missing! Check smpl chunk??";
}
return this.buffer;
}
Expand All @@ -197,6 +196,11 @@ export class Sample{
*/
loadBufferData(smplArr)
{
if(this.sampleRate < 3000)
{
// eos, do not do anything
return;
}
// read the sample data
const audioData = new Float32Array(((this.sampleEndIndex - this.sampleStartIndex) / 2) + 1);
const dataStartIndex = smplArr.currentIndex
Expand All @@ -214,25 +218,11 @@ export class Sample{
}

this.sampleData = audioData;
// // resample
// const rateRatio = 44100 / this.sampleRate;
// const outputLength = Math.floor(this.sampleLength * rateRatio);
// const outputData = new Float32Array(outputLength);
//
//
// for (let i = 0; i < outputLength; i++) {
// const inputIndex = i / rateRatio;
// const floor = Math.floor(inputIndex);
// const ceil = Math.ceil(inputIndex);
// const fraction = inputIndex - floor;
//
// const lowerSample = audioData[floor];
// const upperSample = audioData[ceil];
//
// outputData[i] = lowerSample + (upperSample - lowerSample) * fraction;
// }
// this.sampleData = outputData;
// this.sampleRate = 44100;
this.buffer = new AudioBuffer({
length: this.sampleData.length,
sampleRate: this.sampleRate
});
this.buffer.getChannelData(0).set(audioData);
}

/**
Expand Down Expand Up @@ -271,11 +261,6 @@ export class Sample{
*/
getPlaybackRate(midiNote, overridingRootKey=undefined)
{
// const diff = midiNote - this.samplePitch;
// return 1 + diff / 128;
// const baseDetune = 100 * this.samplePitch// + this.samplePitchCorrection;// this breaks it for some fucking reason
// const cents = midiNote * 100 - baseDetune;
// return Math.pow(2, cents / 1200);
let pitch = this.samplePitch;
if(overridingRootKey)
{
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Generator, generatorTypes} from "../../../soundfont/chunk/generators.js";
import {Sample} from "../../../soundfont/chunk/samples.js";
import {Generator, generatorTypes} from "../../soundfont/chunk/generators.js";
import {Sample} from "../../soundfont/chunk/samples.js";

const EMU_ATTENUATION_CORRECTION = 0.4;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Preset} from "../../../soundfont/chunk/presets.js";
import {Preset} from "../../soundfont/chunk/presets.js";
import {GeneratorTranslator} from "./generator_translator.js";
import {SampleNode} from "./sample_node.js";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Voice} from "./buffer_voice/voice.js";
import {Preset} from "../../soundfont/chunk/presets.js";
import {Preset} from "../soundfont/chunk/presets.js";

const CHANNEL_LOUDNESS = 0.5;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {MidiChannel} from "./midi_channel.js";
import {SoundFont2} from "../../soundfont/soundfont_parser.js";
import {ShiftableByteArray} from "../../utils/shiftable_array.js";
import { arrayToHexString } from '../../utils/other.js'
import {SoundFont2} from "../soundfont/soundfont_parser.js";
import {ShiftableByteArray} from "../utils/shiftable_array.js";
import { arrayToHexString } from '../utils/other.js'

// i mean come on
const VOICES_CAP = 1000;
Expand All @@ -16,6 +16,7 @@ export class Synthetizer {
this.voiceCap = VOICES_CAP;
this.soundFont = soundFont;
this.context = targetNode.context;
this.context.audioWorklet.addModule("spessasynth_lib/synthetizer/worklet_voice/voice_processor.js").then(() => {});

this.volumeController = new GainNode(targetNode.context, {
gain: 1
Expand Down Expand Up @@ -269,8 +270,8 @@ export class Synthetizer {
{
// reset
ch.resetControllers();
ch.setPreset(this.defaultPreset);
ch.percussionChannel = false;
ch.setPreset(this.defaultPreset);

// call all the event listeners
const chNr = ch.channelNumber - 1;
Expand All @@ -290,8 +291,9 @@ export class Synthetizer {
this.onPitchWheel(ch.channelNumber - 1, 64, 0);
}
}
this.midiChannels[DEFAULT_PERCUSSION].setPreset(this.percussionPreset);

this.midiChannels[DEFAULT_PERCUSSION].percussionChannel = true;
this.midiChannels[DEFAULT_PERCUSSION].setPreset(this.percussionPreset);
this.system = "gm2";
}

Expand Down Expand Up @@ -425,9 +427,9 @@ export class Synthetizer {
this.system = "gs";
return;
}

else
// Use for Drum Part
if(messageData[6] === 0x15)
if(messageData[6] === 0x15 && messageData[4] === 0x40)
{
// 0 means channel 10 (default), 1 means 1 etc.
const channel = [9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15][messageData[5] & 0x0F]; // for example 1A means A = 11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* voiceData: WorkletVoice[]}} WorkletVoiceMessage
*/

import {Preset} from "../../../soundfont/chunk/presets.js";
import {Preset} from "../../soundfont/chunk/presets.js";
import {WorkletGeneratorHandler} from "./generator_handler.js";

export class Voice2 extends AudioWorkletNode{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/css/style.css → src/website/css/style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@font-face {
font-family: "Sans";
src: url("../other/OpenSans-Light.ttf");
src: url("../OpenSans-Light.ttf");
}

* {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
text-align: center;
text-shadow: 1px 1px 2px #000;
user-select: none;
white-space: nowrap;
}

.channels_dropdown{
Expand Down Expand Up @@ -141,6 +142,9 @@
border-radius: 5px;
font-size: 16px;
display: block;
flex: 1;
height: var(--voice-meter-height);
white-space: nowrap;
}
.note_killer:hover
{
Expand Down
12 changes: 6 additions & 6 deletions src/index.html → src/website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SpessaSynth</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/sequencer_ui.css">
<link rel="stylesheet" href="css/keyboard_ui.css">
<link rel="stylesheet" href="css/synthesizer_ui.css">
<link rel="stylesheet" href="css/keyboard.css">
<link rel="stylesheet" href='website/css/style.css'>
<link rel="stylesheet" href='website/css/sequencer_ui.css'>
<link rel="stylesheet" href='website/css/keyboard_ui.css'>
<link rel="stylesheet" href='website/css/synthesizer_ui.css'>
<link rel="stylesheet" href='website/css/keyboard.css'>
</head>
<body>
<div class="top_part">
Expand Down Expand Up @@ -38,6 +38,6 @@ <h1 id="title">SpessaSynth: SoundFont2 Javascript Synthetizer</h1>
<h2 id="text_event"></h2>
</div>

<script src="js/website/main.js" type="module"></script> <!-- Here the magic happens ;) -->
<script src='website/main.js' type="module"></script> <!-- Here the magic happens ;) -->
</body>
</html>
6 changes: 3 additions & 3 deletions src/js/website/main.js → src/website/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict"

import {Manager} from "./manager.js";
import {MIDI} from "../midi_parser/midi_loader.js";
import {MIDI} from "../spessasynth_lib/midi_parser/midi_loader.js";

import {SoundFont2} from "../soundfont/soundfont_parser.js";
import {ShiftableByteArray} from "../utils/shiftable_array.js";
import {SoundFont2} from "../spessasynth_lib/soundfont/soundfont_parser.js";
import {ShiftableByteArray} from "../spessasynth_lib/utils/shiftable_array.js";

const TITLE = "SpessaSynth: SoundFont2 Javascript Synthetizer";

Expand Down
17 changes: 8 additions & 9 deletions src/js/website/manager.js → src/website/manager.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {MidiKeyboard} from "../ui/midi_keyboard.js";
import {Synthetizer} from "../midi_player/synthetizer/synthetizer.js";
import {Renderer} from "../ui/renderer.js";
import {Sequencer} from "../midi_player/sequencer/sequencer.js";
import {MIDI} from "../midi_parser/midi_loader.js";
import {MidiKeyboard} from "./ui/midi_keyboard.js";
import {Synthetizer} from "../spessasynth_lib/synthetizer/synthetizer.js";
import {Renderer} from "./ui/renderer.js";
import {Sequencer} from "../spessasynth_lib/sequencer/sequencer.js";
import {MIDI} from "../spessasynth_lib/midi_parser/midi_loader.js";

import {SoundFont2} from "../soundfont/soundfont_parser.js";
import {SequencerUI} from "../ui/sequencer_ui.js";
import {SynthetizerUI} from "../ui/synthetizer_ui.js";
import {SoundFont2} from "../spessasynth_lib/soundfont/soundfont_parser.js";
import {SequencerUI} from "./ui/sequencer_ui.js";
import {SynthetizerUI} from "./ui/synthetizer_ui.js";

export class Manager
{
Expand Down Expand Up @@ -35,7 +35,6 @@ export class Manager
* @param soundFont {SoundFont2}
*/
constructor(context, soundFont) {
context.audioWorklet.addModule("js/midi_player/synthetizer/worklet_voice/voice_processor.js").then(() => {});
// set up soundfont
this.soundFont = soundFont;

Expand Down
File renamed without changes.
Loading

0 comments on commit a2e3b64

Please sign in to comment.