[Date Index]
[Thread Index]
[Author Index]
Re: Error using Manpulate that is NOT obvious (to me)
*To*: mathgroup at smc.vnet.net
*Subject*: [mg96754] Re: Error using Manpulate that is NOT obvious (to me)
*From*: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
*Date*: Tue, 24 Feb 2009 05:44:05 -0500 (EST)
*References*: <gntsab$rh6$1@smc.vnet.net>
Hi Benjamin,
The following will work:
DynamicModule[{f, m, s,
sd = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#",
"B"}, pt, p, o},
Manipulate[
f = N[(440/64) 2^((m + 3)/12)];
s = m - 60;
pt = Mod[m, 12];
p = sd[[pt + 1]];
o = Floor[m/12] - 1;
"MIDI Note Number (0-127)" <> ToString[m] <> " equals " <>
ToString[f] <> " Hertz (8-12600)" <>
", and its SoundNote number (-60 to 67) is " <> ToString[s] <>
", which has the Pitch name of (C to B) " <> ToString[p] <>
" in Octave (-1 to 9) " <> ToString[o] <> ".",
{m, 0, 127, 1},
SaveDefinitions -> True
]
]
I've made several changes, some essential, some a matter of style or
efficiency.
1. Removed the Print function, which printed to the Message box. The
result of the last of a series of concatenated statements is shown as
the result of the Manipulate body. It's now one string using the
StringJoin (<>) and the ToString functions
2. You used Integer to make the result of the division integer. You
should use Round, Floor, Ceiling or the integer division Quotient for
that use.
3. The DynamicModule now surrounds the Manipulate instead of the other
way around
4. Constants (sd) should not be re-assigned again and again
5. Instead of writing pt = Mod[m, 12]; p = sd[[pt + 1]] you could
have used the slightly more elegant pt = Mod[m, 12,1]; p = sd
[[pt]];
Cheers -- Sjoerd
On Feb 23, 12:03 pm, brt... at pdmusic.org wrote:
> Using Mathematica 6.0.2, I can't get this relatively straight forward cod=
e to
> work, Can anyone explain what's wrong and how to fix it. It's
> essentially intended to be musician utility for using the SoundNote
> function which I hope to further elaborate by also converting any
> (MIDI note range frequency) into the appropriate MIDI note number and
> pitch bend values assumming a fine tuning RPN range of +/- 1 semitone,
> allowing 100 cents "sensitivity" to be defined.
>
> Manipulate[
> DynamicModule[{f, m, s, sd, pt, p, o},
> f = N[(440/64) 2^((m + 3)/12)];
> sd = {"C", "C#", "D", "D#", "E", "F",
> "F#", "G", "G#", "A", "A#", "B"};
> s = m - 60;
> pt = Mod[m, 12];
> p = sd[[pt + 1]];
> o = Integer[m/12] - 1;
> Print[
> "MIDI Note Number (0-127)", m,
> " equals ", f, " Hertz (8-12600)",
> ", and its SoundNote number (-60 to 67) is ", s,
> ", which has the Pitch name of (C to B) ", p,
> " in Octave (-1 to 9) ", o, "."
> ]
> ],
> {m, 0, 127, 1},
> SaveDefinitions -> True
> ]
>
> Benjamin Tubb
> using Mathematica 6.0.2
> and still occasionally v3.0.1 <g>
Prev by Date:
**Re: DiscretePlot**
Next by Date:
**Re: Error using Manpulate that is NOT obvious (to me)**
Previous by thread:
**Re: Error using Manpulate that is NOT obvious (to me)**
Next by thread:
**Re: most ChemicalData molecule plots missing? [solved]**
| |