Hallo,
David Powers hat gesagt: // David Powers wrote:
> I'm wondering if I should use something like PyExt to do some of the
> mapping, as I don't know of any simple way to do hash dictionaries in
> PD itself. As a test last night, I built a simple abstraction to take
> notes C C# D etc. and output pitch numbers 0-11, and i found it quite
> tedius to do compared to a function in code such as (this is in PHP
> because that is what I do all day long at my day job):
> function note2number($note) {
> $num = array ('C'=>0,'C#'=>1,'Db'=>1);
> return $num[$note];
> }Well, Pd doesn't have proper hash dictionaries. OTOH Lua has hash dictionaries as its *only* data structure (called "tables" in Lua), so to me it's an ideal complement to Pd. Attached is a quick [note2num] object for pdlua. It also handles multiple modifiers like "Gbbbb" or mixed ones like "Gb#bbb#b". ;) Ciao -- Frank Barknecht _ ______footils.org__
note2num-help.pd
Description: application/puredata
--[[
note2num: convert note names like "C#" or "Bb" or "Ab#bb" to midi note
numbers
-- fbar 2008
--]]
local M = pd.Class:new():register("note2num")
local n2n = {
c = 0,
d = 2,
e = 4,
f = 5,
g = 7,
a = 9,
b = 11,
}
function M:initialize(name, atoms)
self.inlets = 1
self.outlets = 1
return true
end
function M:in_1(sel, atoms)
local s
if not atoms[1] then
s = sel
else
s = atoms[1]
end
assert(type(s) == "string", "only symbols allowed")
s = string.lower(s)
local n, mods = s:match("^([cdefgab])([#b]*)$")
local val = n2n[n]
if mods and val then
local _, b = string.gsub(mods, "b", "b")
local _, h = string.gsub(mods, "#", "#")
val = val + h - b
end
if val then
self:outlet(1, "float", {val})
end
end
_______________________________________________ [email protected] mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
