Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #15470 > unrolled thread

Re: producing a noise

Started byFrancisco Gutierrez <fgutiers2002@yahoo.com>
First post2013-09-18 10:15 +0000
Last post2013-09-18 10:15 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: producing a noise Francisco Gutierrez <fgutiers2002@yahoo.com> - 2013-09-18 10:15 +0000

#15470 — Re: producing a noise

FromFrancisco Gutierrez <fgutiers2002@yahoo.com>
Date2013-09-18 10:15 +0000
SubjectRe: producing a noise
Message-ID<l1bufc$for$1@smc.vnet.net>
This is a treat Alexei, many thanks! (and yes, the calculation has an iterator in it)
Francisco


________________________________

From: Alexei Boulbitch <Alexei.Boulbitch@iee.lu>
Sent: Monday, September 16, 2013 4:27 AM
Subject: Re: producing a noise


Dear Group:
Suppose I am running a simulation, and go on to work on another issue. I would like Mathematica to produce a sound as soon as it ends (but not always, only when told so).
I imagine this is quite easy, but don't know how. Any ideas?
Thanks
Francisco

Hi, Francisco,

Below I am sending you one program that has a comparable functionality. This is a toy to teach a school pupil of the first classes to count. As the outcome they receive a sound signal, the one in the case of a correct answer different from that in the case of the incorrect one. In addition two short cartoons are played after a correct and an incorrect answers correspondingly. I am afraid that to view the program you will need to save the notebook with this code into some folder, and place two gif images or gif movies with the names (1) cataround.gif and (2) argue01.gif into this same folder.

Now to the point: the two sounds used in the program are kept in the form of the two functions g1[ ] and g2[ ]. It is done in the beginning of the program. You then apply the functions where you need. This may include the place where your calculation is finished. In my case they have been applied in the very end depending upon the correctness of the answer given. The functions g1 and g2 are stand alone ones. You may play them just by evaluation.

You did not write, what type of calculation do you do there. I can imagine that if your procedure has an iterator in it, (like, say, a Table or a loop) the sound may play as soon as the iterator achieves a certain value.

Find the program below. Have fun, Alexei

right := 0;
wrong := 0;
Clear[cat, dummy];
cat = Import[NotebookDirectory[] <> "cataround.gif"];
dummy = Import[NotebookDirectory[] <> "argue01.gif"];
DarkRed = RGBColor[0.9, 0, 0];



g1[] :=
 EmitSound[
   Sound[{SoundNote["E", 0.5], SoundNote["C", 0.5],
   SoundNote["E", 0.5], SoundNote["C", 0.5], SoundNote["F", 0.5],
   SoundNote["E", 0.5], SoundNote["D", 1]}]];
g2[] := EmitSound[
=
   Sound[{SoundNote["G", 0.2], SoundNote["G", 0.2],
     SoundNote[=
"G", 0.2], SoundNote["Eb", 7]}]];


sign = RandomChoice[{"+", "-"}]=
;
a = RandomInteger[{0, 100}];
b = If[sign == "+", RandomInteger[{0, 100 - a}],
   FromDigits[{RandomInteger[{0, IntegerDigits[a][[1]]}],
     RandomInteger[{0, IntegerDigits[a][[2]]}]}]];
countOK = 0;
lst = {};
c = "??";

Panel@Column[{
           Row[{    
             Dynamic@
      Button[Style[1, 30], lst = Append[lst, 1]; c = FromDigits[lst]],
      Dynamic@
      Button[Style[2, 30], lst = Append[lst, 2]; c = FromDigits[lst]],
           Dynamic@
      Button[Style[3, 30], lst =
 Append[lst, 3]; c = FromDigits[lst]],
              
    Dynamic@Button[Style[4, 30], lst = Append[lst, 4];
       c = FromDigits[lst]],
            
    Dynamic@Button[Style[5, 30], lst = Append[lst, 5];
       c = FromDigits[lst]],
       Dynamic@
      Button[Style[6, 30], lst = Append[lst, 6]; c = FromDigits[lst]],
             Dynamic@
    Button[Style[7, 30], lst = Append[lst, 7]; c = FromDigits[lst]], Dynamic@      But= ton[Style[8, 30], lst = Append[lst, 8]; c = FromDigits[lst]],
       Dynamic@Button[Style[9, 30], lst = Append[lst, 9];
       c = FromDigits[lst]],

    Dynamic@Button[Style[0, 30], lst = Append[lst, 0];
     c = FromDigits[lst]]
                                    }], "",
  Panel@Row[{Style[a, 28, Bold, DarkRed],
      Style[sign, 28, Bold, DarkRed], Style[b, 28, Bold, DarkRed],
      Style[" = ", 28 , Bold, DarkRed],
      Style[Dynamic[c], 28, Bold, DarkRed]}], Spacer[{10, 20}],  

   Button["OK", countOK++;

    If[countOK > 1, wrong++;
     mov = ListAnimate[dummy, AnimationRepetitions -> 1,
       AnimatorElements -> None]; g2[], If[sign == "+",

      If[c == a + b, right++;
       mov = ListAnimate[cat, AnimationRepetitions -> 1, AnimatorElements -> None]; g1[], wrong++;
       mov = ListAnimate[dummy, AnimationRepetitions -> 1,
         AnimatorElements -> None]; g2[]],
      If[c == a - b, right++; mov = ListAnimate[cat, AnimationRepetitions -> 1,
     AnimatorElements -> None]; g1[], wrong++;
       mov = ListAnimate[dummy, AnimationRepetitions -> 1,
         AnimatorElements -> None]; g2[]]
                          ]           ]               ] ,
   "",

   Dynamic[mov], "",

   Column[{
  Row[{Style["Richtig:", 20], Spacer[10],
       Style[Dynamic[right], 20, Bold, RGBColor[0, 0.8, 0]]}], "",
     Row[{Style["Falsch:", 20], Spacer[15],
       Style[Dynamic[wrong], 20, Bold, RGBColor[0.8, 0, 0]]}], "",
     Row[{Style["Wiefiel?", 20], Spacer[10], Style[Dynamic[right + wrong], 20]}]
     }, Alignment -> Center],
   "",

   Row[{
     Button[Style["Weiter", 16],
      SelectionMove[EvaluationNotebook[], All, EvaluationCell] ;
      SelectionMove[EvaluationNotebook[], Previous,
     Cell] SelectionEvaluate[EvaluationNotebook[]],
      ImageSize-> {100, 20}],
     Spacer[10],
     Button[Style["Aufh=F6ren", 16], NotebookClose[],
      ImageSize -> {100, 20}]
     }]
           }, Alignment -> Center]



(*   Here the program ends  *)


AAlexei BOULBITCH, Dr., habil.
IEE S.A.=0AZAEWeiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone :  +352-2454-2566
Office fax:       +352-2454-3566
mobile phone:  +49 151 52 40 66 44

e-mail: alexei.boulbitch@iee.lu

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web