MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Error using Manpulate that is NOT obvious (to me)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96760] Re: [mg96744] Error using Manpulate that is NOT obvious (to me)
  • From: "Ailton Andrade de Oliveira" <oailton at taboanense.com.br>
  • Date: Tue, 24 Feb 2009 05:45:15 -0500 (EST)
  • References: <200902231004.FAA28202@smc.vnet.net>

Hi,

	I've done a little rewriting. Manipulate should be inside DynamicModule.
There were other little changes but I think you should try the following
to see if it helps.


DynamicModule[{f, s, sd, pt, p, o},
    Manipulate[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 = Quotient[m, 12] - 1;
     StringJoin["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) ", p,
      " in Octave (-1 to 9) ", ToString[o], "."], {m, 0, 127, 1},
     SaveDefinitions -> True]]



	I think the main problem was caused by the fact that were two "m"
variables: one used by Manipulate and other localized by DynamicModule.
The variables localized by DynamicModule are not meant to be visible from
outside.

	The main idea is to consider DynamicModule as a scoping construct and it
is not a natural situation to interfere with its variables outside of it.
So, Manipulate was controlling its own "m" variable, and all the other
variables in the original formulation were left uninitialized. What was
getting printed were the unique names associated with the localized
variables instead of the values you were supposed to be waiting for.



Em Mon, 23 Feb 2009 07:04:02 -0300, <brtubb at pdmusic.org> escreveu:

> Using Mathematica 6.0.2, I can't get this relatively straight forward  
> code 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>
>



-- 

"If knowledge can create problems, it is not
     through ignorance that we can solve them."
      - Isaac Asimov


  • Prev by Date: Re: Error using Manpulate that is NOT obvious (to me)
  • Next by Date: Re: Exporting data into a file, OpenWrite
  • Previous by thread: Error using Manpulate that is NOT obvious (to me)
  • Next by thread: Re: Error using Manpulate that is NOT obvious (to me)