Just wanna figure out if there is a decent way to add a same option to multiple functions simultaneously.
For example I have a series of SoundNote
:
Sound[{SoundNote["D4", {0.4, 0.2}], SoundNote["G4", {0.6, 0.2}], SoundNote["B4", {0.8, 0.2}], SoundNote["D5", {1, 0.2}], SoundNote["A4", {1.2, 0.2}], SoundNote["E4", {1.4, 0.2}], SoundNote["G4", {1.6, 0.2}], SoundNote["A4", {1.8, 0.2}]}]
And now I want to add an option SoundVolume -> 1/2
to the arguments of all functions in the list and make it like:
Sound[{SoundNote["D4", {0.4, 0.2},SoundVolume->1/2], SoundNote["G4", {0.6, 0.2},SoundVolume->1/2], SoundNote["B4", {0.8, 0.2},SoundVolume->1/2], SoundNote["D5", {1, 0.2},SoundVolume->1/2], SoundNote["A4", {1.2, 0.2},SoundVolume->1/2], SoundNote["E4", {1.4, 0.2},SoundVolume->1/2], SoundNote["G4", {1.6, 0.2},SoundVolume->1/2], SoundNote["A4", {1.8, 0.2},SoundVolume->1/2]}]
Is there any way to add the option instead of adding them one by one?
I've tried combining pure functions and Append
like this:
Sound[Append[#,SoundVolume->1/2]& /@{SoundNote["D4", {0.4, 0.2}], SoundNote["G4", {0.6, 0.2}], SoundNote["B4", {0.8, 0.2}], SoundNote["D5", {1, 0.2}], SoundNote["A4", {1.2, 0.2}], SoundNote["E4", {1.4, 0.2}], SoundNote["G4", {1.6, 0.2}], SoundNote["A4", {1.8, 0.2}]}]
But it didn't work as it seems like the compiler sees SoundVolume -> 1/2
as an option for Append
.
list /. SoundNote[args__] :> SoundNote[args, SoundVolume -> 1/2]
. $\endgroup$ – J. M.'s ennui♦ Jun 21 '15 at 9:47SoundVolume->1/2
as an option forSound
instead of an option for every singleSoundNote
. $\endgroup$ – Karsten 7. Jun 21 '15 at 9:52SoundNote
usingSetOptions
:SetOptions[SoundNote, SoundVolume -> 1/2]
. $\endgroup$ – Karsten 7. Jun 21 '15 at 9:54Append
works in version 10.1.0 under Windows. Which version are you using? $\endgroup$ – Mr.Wizard Jun 21 '15 at 10:34