Skip to content

Commit

Permalink
Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
samouri committed Jan 15, 2024
1 parent 6093146 commit 7aab9f1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 52 deletions.
99 changes: 48 additions & 51 deletions src/features/midi/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,59 @@
import { Midi } from "@tonejs/midi"
import { Midi } from '@tonejs/midi'
import fs from 'fs'
import { Song, Track, Tracks, Bpm, SongNote } from '@/types'

export function convertBase64MidiToSong(base64Midi: string) {
const binaryMidi = Buffer.from(decodeURIComponent(base64Midi), 'base64')
console.log(binaryMidi)
const midi = new Midi(binaryMidi)
console.log(midi)
let tracks: Tracks = {}
const bpms: Array<Bpm> = []
const notes: Array<SongNote> = []

let index: number = 0
for (const track of midi.tracks) {
const newTrack: Track = {
instrument: track.instrument.name.replace(/ /g,"_"),
name: "Track" + index
}
tracks[index] = {...newTrack}
for (const note of track.notes) {
const newNote: SongNote = {
type: "note",
midiNote: note.midi,
duration: note.duration,
track: index,
velocity: note.velocity,
time: note.time,
measure: note.bars // ??
}
notes.push(newNote)
}
const binaryMidi = Buffer.from(decodeURIComponent(base64Midi), 'base64')
const midi = new Midi(binaryMidi)
let tracks: Tracks = {}
const bpms: Array<Bpm> = []
const notes: Array<SongNote> = []

index++
let index: number = 0
for (const track of midi.tracks) {
const newTrack: Track = {
instrument: track.instrument.name.replace(/ /g, '_'),
name: 'Track' + index,
}
tracks[index] = { ...newTrack }
for (const note of track.notes) {
const newNote: SongNote = {
type: 'note',
midiNote: note.midi,
duration: note.duration,
track: index,
velocity: note.velocity,
time: note.time,
measure: note.bars, // ??
}
notes.push(newNote)
}

index++
}

for (const tempos of midi.header.tempos) {
const newBpm: Bpm = {
time: tempos.time? tempos.time : 0,
bpm: tempos.bpm
}
bpms.push(newBpm)
for (const tempos of midi.header.tempos) {
const newBpm: Bpm = {
time: tempos.time ? tempos.time : 0,
bpm: tempos.bpm,
}

// Not enough info to fill everything
const song: Song = {
tracks: tracks,
duration: midi.duration,
measures: [],
notes: notes,
bpms: bpms,
timeSignature: undefined,
keySignature: 'C',
items: notes,
backing: undefined
};
bpms.push(newBpm)
}

console.log(song)
// Not enough info to fill everything
const song: Song = {
tracks: tracks,
duration: midi.duration,
measures: [],
notes: notes,
bpms: bpms,
timeSignature: undefined,
keySignature: 'C',
items: notes,
backing: undefined,
}

return song
}
console.log(song)

return song
}
2 changes: 1 addition & 1 deletion src/icons/StopRecord.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IconProps } from '@/icons'
export function StopRecord(props: IconProps) {
return (
<svg width={props.size} height={props.size} viewBox="0 0 27 27" {...props}>
<rect x="3" y="3" width="21" height="21" className='fill-red-500 hover:fill-purple-hover'/>
<rect x="3" y="3" width="21" height="21" className="fill-red-500 hover:fill-purple-hover" />
</svg>
)
}

0 comments on commit 7aab9f1

Please sign in to comment.