Re: Programming Fail
- To: mathgroup at smc.vnet.net
- Subject: [mg132031] Re: Programming Fail
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Tue, 19 Nov 2013 02:58:35 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
- References: <20131117232215.A9F846A15@smc.vnet.net>
Before using pitchMap you need integers rather than strings.
A = NestList[
StringReplace[#,
{"0" -> "2", "2" -> "12", "1" -> "23",
"3" -> "45", "4" -> "56"}] &,
"0", 7] // ToExpression //
IntegerDigits // Flatten;
pitchMap = {0 -> "B4", 1 -> "C4", 2 -> "D4",
3 -> "E4", 4 -> "F4", 5 -> "G4", 6 -> "A4"};
Sound[Thread[SoundNote[A] /. pitchMap]]
or
Sound[SoundNote /@ A /. pitchMap]
Bob Hanlon
On Sun, Nov 17, 2013 at 6:22 PM, Dean Rosenthal <deanrosenthal at gmail.com>wrote:
> Hi:
>
> My question is going to take all of you about a split second to answer.
> Sadly, programming is something I seem to be congenitally incapable of
> teaching myself and doing well. I usually just cut and paste specifics
> into prewritten algorithms.
>
> If you do this
>
> pitchMap = {1 -> {"C4", "D4"}, 2 -> "D4", 3 -> "E4", 4 -> "F4", 5 -> "G4"};
>
> Sound[Thread[SoundNote[Flatten[IntegerPartitions[5]] /. pitchMap]]]
>
>
> You get a music player and can play the result.
>
>
> If you do this:
>
>
> A = NestList[
> StringReplace[#, {"0" -> "2", "2" -> "12", "1" -> "23", "3" -> "45",
> "4" -> "56"}] &, "0", 7]
>
> pitchMap = {0 -> "B4", 1 -> "C4", 2 -> "D4", 3 -> "E4", 4 -> "F4", 5 ->
> "G4",
> 6 -> "A4"};
>
> Sound[Thread[SoundNote[Flatten[A]] /. pitchMap]]]
>
>
> You get nothing, just output. See what I did there? I substituted,
> because that's what you do if you don't know how to program! On the face
> of things, I can't see why it wouldn't work, but I've wasted at least an
> hour going through documentation and Googling and trying different
> approaches. I'm not a programmer and I can't seem to teach myself how to
> do this, ideas?
>
>
> Thanks,
>
>
> Dean
>
>
>
- References:
- Programming Fail
- From: Dean Rosenthal <deanrosenthal@gmail.com>
- Programming Fail