Skip to content

Commit

Permalink
Fix sticky notes
Browse files Browse the repository at this point in the history
  • Loading branch information
littletsu committed Aug 12, 2024
1 parent a687618 commit 590516e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
// imports
import {reactive, ref} from "vue";
import {ref} from "vue";
// component imports
import UIContainer from "./components/ui/UIContainer.vue";
Expand All @@ -13,16 +13,16 @@ import SoundHandler, { NoteEventPayload } from "./lib/SoundHandler";
// refs
const started = ref<boolean>(false)
const sound_events = reactive<NoteEventPayload[]>([])
// const sound_events = reactive<NoteEventPayload[]>([])
const InstrumentUI_ref = ref<InstanceType<typeof InstrumentUI>>();
const NetHandler_ref = ref<InstanceType<typeof NetHandler>>();
// functions
function push_payload(payload: NoteEventPayload) {
console.log(`received event: ${payload.event} - ${payload.note}`);
sound_events.push({event: payload.event, note: payload.note})
InstrumentUI_ref.value?.process_sound_events()
// sound_events.push(payload)
InstrumentUI_ref.value?.process_sound_events(payload)
}
// This one must only be called when the user produces the input, not any remote
Expand Down Expand Up @@ -58,9 +58,9 @@ async function initSoundHandler() {
</UIContainer>

<UIContainer :title="'instrument'">
<!-- v-model="sound_events" -->
<InstrumentUI
ref="InstrumentUI_ref"
v-model="sound_events"
@sound_handler_initialized="started = true"
/>
</UIContainer>
Expand Down
32 changes: 17 additions & 15 deletions src/components/InstrumentUI.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import InstrumentSwitcher from "./InstrumentSwitcher.vue";
import SoundHandler, { NoteEventPayload } from "../lib/SoundHandler.ts";
import {onMounted, ref } from "vue";
let sound_events = defineModel<NoteEventPayload[]>()
// let sound_events = defineModel<NoteEventPayload[]>()
let soundHandler: SoundHandler;
let instrument_selected: string = "meow"
Expand All @@ -19,20 +19,22 @@ defineExpose({
process_sound_events
})
async function process_sound_events() {
let new_sound_events = sound_events.value
if(new_sound_events === undefined) return;
try {
let promises = []
for (const note_event of new_sound_events) {
promises.push(soundHandler.play(note_event.event, note_event.note, instrument_selected))
sound_events.value?.shift()
}
await Promise.allSettled(promises);
} catch (e) {
console.log('HELLO!')
console.error(e)
}
async function process_sound_events(note_event: NoteEventPayload) {
// let new_sound_events = sound_events.value
// console.log(new_sound_events)
// if(new_sound_events === undefined) return;
// try {
// let promises = []
// for (const note_event of new_sound_events) {
// promises.push()
// sound_events.value?.shift()
// }
// await Promise.allSettled(promises);
// } catch (e) {
// console.log('HELLO!')
// console.error(e)
// }
soundHandler.play(note_event.event, note_event.note, instrument_selected)
}
async function read_file(files: any) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/net/PotatoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class PotatoClientProcessing extends EventEmitter<PotatoClientEvents> {
console.warn(`Got ${data} from server ${this.serverId}!`)
return;
}
console.log(data)
console.log("client got", data)
if(typeof(data) !== "object") {
console.warn(`Received unknown data type from server ${this.serverId}! Expected "object" got "${typeof(data)}"`)
return;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/net/PotatoServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export default class PotatoServer {
console.warn(`Got ${data} from ${id}!`)
return;
}
console.log(data)
console.log("server got", data)
if(typeof(data) !== "object") {
console.warn(`Received unknown data type from ${id}! Expected "object" got "${typeof(data)}"`)
return;
Expand Down

0 comments on commit 590516e

Please sign in to comment.