Skip to content

Commit

Permalink
Merge pull request #1 from schollz/piano
Browse files Browse the repository at this point in the history
Piano
  • Loading branch information
schollz authored Mar 31, 2021
2 parents b52b129 + df9200f commit d9af170
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/mx.samples.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ end
function MxSamples:new(args)
local l=setmetatable({},{__index=MxSamples})
local args=args==nil and {} or args
l.debug = args.debug
l.debug = args.debug -- true --args.debug
l.instrument={} -- map instrument name to list of samples
l.buffer=0
l.voice={} -- list of voices and how hold they are
Expand Down
6 changes: 4 additions & 2 deletions mx.samples.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- mx.samples v0.2.3
-- mx.samples v0.3.0
-- download and play samples
--
-- llllllll.co/t/mxsamples
Expand All @@ -21,6 +21,8 @@ available_instruments={
{name="box violin",size=8*1.5},
{name="cello",size=22*1.5},
{name="cello pad",size=4*1.5},
{name="claus piano",size=616},
{name="claus piano wpedal",size=614},
{name="dictaphone",size=18},
{name="discord choir",size=18},
{name="ghost piano",size=40*1.5},
Expand All @@ -42,7 +44,7 @@ function init()
do return end
end
if (data[1]==144 or data[1]==128) then
tab.print(data)
-- tab.print(data)
if data[1]==144 and data[3] > 0 then
skeys:on({name=available_instruments[instrument_current].id,midi=data[2],velocity=data[3]})
elseif data[1]==128 or data[3] == 0 then
Expand Down
50 changes: 50 additions & 0 deletions samples/extract_single_wav.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# <group name="KU100 F notes_with_pedal" loCC64="64" hiCC64="127">
# <sample hiNote="21" loNote="21" rootNote="21" start="400000" end="1200000" path="samples/Claustrophobic Piano KU 100_NR.wav" seqPosition="1" loVel="120" hiVel="127"/>
# <sample hiNote="21" loNote="21" rootNote="21" start="400000" end="1200000" path="samples/Claustrophobic Piano KU 100_NR.wav" seqPosition="2"
import os

from xml.etree import cElementTree as ET
from icecream import ic

mics = ["KU100", "MIX456", "M149"]
wwopedal = ["with_pedal", "without_pedal"]

for _, mic in enumerate(mics):
for _, pedaltype in enumerate(wwopedal):
try:
os.mkdir(f"{mic}_{pedaltype}")
except:
pass
lines = open(f"Claustrophobic Piano ({mic}).dspreset", "r").read().split("\n")
dynamic = "F"
getsamples = False
for line in lines:
line = line.strip()
if line.startswith("<group name"):
getsamples = False
if f"MF notes_{pedaltype}" in line:
dynamic = 2
getsamples = True
elif f" P notes_{pedaltype}" in line:
dynamic = 1
getsamples = True
elif f" F notes_{pedaltype}" in line:
dynamic = 3
getsamples = True
elif line.startswith("<sample") and getsamples:
r = ET.fromstring(line)
try:
note = int(r.get("rootNote"))
except:
continue
source = r.get("path")
sstart = float(r.get("start")) / 48000.0
duration = float(r.get("end")) / 48000.0 - sstart
variation = int(r.get("seqPosition"))
ic(line, dynamic, note, sstart, duration, variation)
# <midinote>.<dynamic>.<dynamics>.<variation>.<release>.wav
fname = f"{note}.{dynamic}.3.{variation}.0.wav"
if not os.path.exists(f"{mic}_{pedaltype}/{fname}"):
cmd = f"ffmpeg -y -i '{source}' -ss '{sstart}' -t '{duration}' {mic}_{pedaltype}/{fname}"
print(cmd)
os.system(cmd)

0 comments on commit d9af170

Please sign in to comment.