-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from vladkorotnev/develop
Release v3.0
- Loading branch information
Showing
94 changed files
with
9,399 additions
and
2,399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,73 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# this is very jank, do not expect it to work as is | ||
# it worked for some melodies though | ||
|
||
import pdb | ||
from sys import argv | ||
from mido import MidiFile | ||
import freq_note_converter | ||
|
||
mid = MidiFile(argv[1]) | ||
name = argv[2] | ||
|
||
last_time = 0 | ||
evts = [] # of (freq in hz or 0, delay in ms) | ||
ended = False | ||
|
||
class Event(): | ||
def __init__(self, kind, chan, arg): | ||
self.kind = kind | ||
self.chan = chan | ||
self.arg = arg | ||
|
||
def __str__(self): | ||
return f" {{{self.kind}, {str(self.chan)}, {str(int(self.arg))}}}," | ||
|
||
class Comment(): | ||
def __init__(self, s): | ||
self.content = s | ||
self.kind = "REM" | ||
|
||
def __str__(self): | ||
return f" /* {self.content} */" | ||
|
||
evts = [] | ||
|
||
def prev_note_off_event(chan): | ||
for i in range(1,len(evts)+1): | ||
e = evts[-i] | ||
if e.kind == "FREQ_SET" and e.arg == 0 and e.chan == chan: | ||
return e | ||
elif e.kind == "DELAY": | ||
return None | ||
return None | ||
|
||
for msg in mid: | ||
print(msg) | ||
if msg.type == "note_on" or msg.type == "note_off": | ||
print(msg) | ||
if msg.time > 0 and len(evts) > 0 and evts[-1][1] == 0: | ||
evts[-1][1] = int(msg.time * 1000) | ||
if msg.time > 0.005: | ||
evts.append(Event("DELAY", 0, msg.time * 1000)) | ||
if msg.type == "note_on" and msg.velocity > 0: | ||
evts.append([int(freq_note_converter.from_note_index(msg.note).freq), 0, ""]) | ||
existing_evt = prev_note_off_event(msg.channel) | ||
if existing_evt is not None: | ||
existing_evt.arg = freq_note_converter.from_note_index(msg.note).freq | ||
else: | ||
evts.append(Event("FREQ_SET", msg.channel, freq_note_converter.from_note_index(msg.note).freq)) | ||
else: | ||
# note off | ||
evts.append([0, 0, ""]) | ||
evts.append(Event("FREQ_SET", msg.channel, 0)) | ||
elif msg.type == "end_of_track": | ||
print(msg) | ||
if ended: | ||
raise Exception("WTF, already ended") | ||
ended = True | ||
if evts[-1][0] == 0: | ||
# pause exists, just extend it | ||
evts[-1][1] = int(msg.time * 1000) | ||
else: | ||
evts.append([0, int(msg.time*1000), ""]) | ||
evts.append(Event("DELAY", 0, msg.time * 1000)) | ||
elif msg.type == "marker": | ||
evts[-1][2] = msg.text | ||
|
||
if msg.time > 0.005: | ||
evts.append(Event("DELAY", 0, msg.time * 1000)) | ||
evts.append(Comment(msg.text)) | ||
if msg.text == "LOOP": | ||
evts.append(Event("LOOP_POINT_SET", 0, 0)) | ||
|
||
print(evts) | ||
|
||
print("static const melody_item_t "+name+"_data[] = {") | ||
i = 0 | ||
while i < len(evts): | ||
if evts[i][0] != 0 or evts[i][1] != 0: | ||
print(" {"+str(evts[i][0])+", "+str(evts[i][1])+"}, ") | ||
if evts[i][2] != "": | ||
print(" ") | ||
print(" // " + evts[i][2]) | ||
i+=1 | ||
for e in evts: | ||
print(str(e)) | ||
print("};") | ||
|
||
print("const melody_sequence_t "+name+" = MELODY_OF("+name+"_data);") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import sys | ||
from pathlib import Path | ||
|
||
IMG_IN=sys.argv[1] | ||
IMG_OUT=sys.argv[2] if len(sys.argv) > 2 else str(Path(IMG_IN).with_suffix(''))+"_pretty.png" | ||
|
||
PIX_COLOR=(0, 210, 242) | ||
PIX_SIZE=4 | ||
PIX_PITCH_H=1 | ||
PIX_PITCH_W=1 | ||
|
||
from PIL import Image, ImageFilter | ||
im = Image.open(IMG_IN, 'r') | ||
src = im.load() | ||
|
||
width, height = im.size | ||
|
||
out_img = Image.new(mode="RGB", size=(width * (PIX_SIZE + PIX_PITCH_H), height * (PIX_SIZE + PIX_PITCH_H))) | ||
|
||
for y in range(height): | ||
for x in range(width): | ||
v = src[x, y] | ||
for dy in range(PIX_SIZE): | ||
for dx in range(PIX_SIZE): | ||
out_x = x * (PIX_SIZE + PIX_PITCH_W) + dx | ||
out_y = y * (PIX_SIZE + PIX_PITCH_H) + dy | ||
if out_x < out_img.width and out_y < out_img.height: | ||
out_img.putpixel((out_x, out_y), PIX_COLOR if v > 0 else (0, 0, 0)) | ||
|
||
out_img.filter(ImageFilter.GaussianBlur(radius=PIX_SIZE/10)).save(IMG_OUT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#-*- coding: utf-8 -*- | ||
|
||
# Super jank converter from 8bit WAV into RLE PWM + preview | ||
# Not reading the header or anything hence super jank | ||
|
||
import sys | ||
|
||
MARGIN = 4 | ||
|
||
fname = sys.argv[1] | ||
sname = sys.argv[2] | ||
oname = sys.argv[3] if len(sys.argv) >= 4 else None | ||
sdata = open(fname, 'rb').read() | ||
outf = None | ||
if oname is not None: | ||
outf = open(oname, 'wb') | ||
outf.write(sdata[:0x28]) | ||
|
||
sdata = sdata[0x28::] | ||
i = 0 | ||
min = 999 | ||
max = 0 | ||
sts = 0xFF | ||
last_sts = 0xFF | ||
rle_buf = [0] | ||
|
||
def median(data): | ||
x = list(data) | ||
x.sort() | ||
mid = len(x) // 2 | ||
return (x[mid] + x[~mid]) / 2.0 | ||
|
||
med = median(sdata) | ||
print("Median", med) | ||
HIGH = med + MARGIN | ||
LO = med - MARGIN | ||
|
||
while i < len(sdata): | ||
curSample = sdata[i] | ||
if curSample >= HIGH: | ||
sts = 255 | ||
elif curSample <= LO: | ||
sts = 1 | ||
if curSample < min and curSample > 0: | ||
min = curSample | ||
if curSample > max and curSample > 0: | ||
max = curSample | ||
if outf is not None: | ||
outf.write(bytes([sts, sts])) | ||
if sts != last_sts: | ||
rle_buf.append(0) | ||
last_sts = sts | ||
if rle_buf[-1] == 255: | ||
rle_buf.append(0) | ||
rle_buf.append(0) | ||
rle_buf[-1] += 1 | ||
i += 2 | ||
|
||
print(f"static const uint8_t {sname}_rle_data[] = {{" + str(rle_buf)[1::][:-1:] + "};") | ||
print(f"static const rle_sample_t {sname} = {{ .sample_rate = 4000, .root_frequency = 524 /* C5 */, .rle_data = {sname}_rle_data, .length = {len(rle_buf)} }};") |
Oops, something went wrong.