I want to be able to define my own musical notes from the ones provided by Mathematica (just as I can define my own data types using standard ones in C programming language). For example, I want to be able to use this as a musical note (call it "E[Flat]F" = Gamaka["E[Flat]", "F"]) where

Gamaka[X_, Y_] := Sound[{SoundNote[ X, 0.15, "Violin"], SoundNote[ Y, 0.02, "Violin"], 
SoundNote[ X, 0.15, "Violin"]}]

But I am not sure how to use this to generate sound such as

Sound[SoundNote[{"CG", "GF", "EC"}, 1, "Violin"]]

where "CG" = Gamaka["C","G"] etc.


1 Answer 1


How about this? It will split the strings and even allow for sharps/flats and numbers.

Gamaka[{X_, Y_}, voice_] := {
  SoundNote[X, 0.15, voice],
  SoundNote[Y, 0.02, voice],
  SoundNote[X, 0.15, voice]}
GamakaSeq[notes_, voice_] := Gamaka[
    StringCases[#, RegularExpression["([A-G][#\[Flat]b]?\\d*)"]]
    , voice] & /@ notes

 GamakaSeq[{"CG", "G#F", "EC", "CG", "GF", "C4C4"}, "Violin"]
  • 1
    $\begingroup$ Thanks, Flinty, I will work with this. Though I feel Mathematica should make this more formal the way C programming language has made the definition of new data types formal. $\endgroup$ Jun 7, 2020 at 5:38
  • $\begingroup$ Yeah - or OO like e.g Sound takes objects with a note interface 'Soundable'. There are other places where I don't like how Mathematica uses strings e.g integration and classify methods, but I suppose it's easier for the developers that way. $\endgroup$
    – flinty
    Jun 7, 2020 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.