Emitting a constant sound or note (no interruptions) for a fixed duration is easy, but a dynamic duration, not so easy.
$\begingroup$
$\endgroup$
2
-
$\begingroup$ Is this related? I mean the core method given by @SimonWoods. The locator can be easily transformed to MouseOver. mathematica.stackexchange.com/questions/5304/… $\endgroup$– Vitaliy KaurovCommented Aug 20, 2012 at 20:17
-
$\begingroup$ Yes, thanks @vitalykaurov. I think it is related but it still does not generate a perfectly constant sound (free of quick pauses) for a dynamic amount of time. $\endgroup$– M.R.Commented Aug 20, 2012 at 20:31
Add a comment
|
2 Answers
$\begingroup$
$\endgroup$
5
Is this satisfactory?
EventHandler[
Framed@"Play flute",
{"MouseEntered" :> EmitSound[Sound@SoundNote["C", 10*^10, "Flute"]],
"MouseExited" :> EmitSound[Sound@SoundNote[SoundVolume -> 0]] }]
-
$\begingroup$ we answered a couple of seconds apart... although your continuous notion is much larger than mine... $\endgroup$ Commented Aug 20, 2012 at 18:24
-
-
$\begingroup$ I don't get any sound from this on v7; before I try to debug, any idea why? $\endgroup$ Commented Aug 23, 2012 at 11:26
-
$\begingroup$ @Mr.Wizard, no. If EmitSound run separately works, I would test those events with a
Print
$\endgroup$– RojoCommented Aug 23, 2012 at 12:33 -
$\begingroup$
"MouseEntered"
and"MouseExited"
are apparently not recognized in version 7. $\endgroup$ Commented Aug 23, 2012 at 12:39
$\begingroup$
$\endgroup$
6
Do you mean something like this:
Mouseover[off,Dynamic[Refresh[EmitSound[Play[Sin[700 t + 25 t Sin[350 t]], {t, 0, 1}]],
UpdateInterval -> 1]; on]]
UPDATE - re-edited
For a "continuous" sound
Mouseover[
Dynamic[EmitSound[Sound[SoundNote["C", 1, "Violin"], SoundVolume -> 0]]; off,
UpdateInterval -> 1],
Dynamic[EmitSound[Sound[SoundNote["C", 500, "Violin"]]]; on,
UpdateInterval -> 1]]
UPDATE 2
Based on @Rojo EventHandler
code, here's an idea for organizing different sound effects on the same notebook:
with the help of NotebookDynamicExpression
:
SetOptions[EvaluationNotebook[], NotebookDynamicExpression :> Dynamic[
Which[
inst == "quiet",
EmitSound[Sound[SoundNote[], SoundVolume -> 0]],
True,
EmitSound[Sound[SoundNote[note, 500, inst]]]
],
TrackedSymbols :> {inst}]
]
and here is a small interface:
notes = {"C", "D", "E", "F", "G", "A", "B"}; instruments = {"Violin",
"Flute", "Piano", "Guitar"};
Grid[Map[EventHandler[
Framed[#[[2]]], {"MouseEntered" :> {inst = #[[1]];
note = #[[2]];}, "MouseExited" :> {inst = "quiet"}}] &,
Table[{i, n}, {i, instruments}, {n, notes}], {2}],
ItemSize -> {2, 2}]
(sorry for the formatting, I still have troubles with this...)
-
1$\begingroup$ This is nice but is not constant, the breaks inbetween are what I'm trying to avoid. $\endgroup$– M.R.Commented Aug 20, 2012 at 18:07
-
$\begingroup$ @Mike I'm still looking for a solution for that... $\endgroup$ Commented Aug 20, 2012 at 18:08
-
$\begingroup$ @rojo Nice, but I still hear momentary pauses. And did you know UpdateInterval -> 1 is an option to Dynamic, you don't need the Refresh call $\endgroup$– M.R.Commented Aug 20, 2012 at 20:20
-
$\begingroup$ @Mike, that thing you wrote was for me or for Fonseca? I don't here any pauses in mine. Beware if you have Fonseca's output showing too when you try mine, because it updates every second to "shut the sound up", so it would shut mine $\endgroup$– RojoCommented Aug 21, 2012 at 3:39
-
$\begingroup$ @Rojo Quite right! Your solution has no pauses, so I will accept it, thanks. $\endgroup$– M.R.Commented Aug 21, 2012 at 5:25