# Composite musical notes

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.

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

Sound[
GamakaSeq[{"CG", "G#F", "EC", "CG", "GF", "C4C4"}, "Violin"]
]

• 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. Jun 7 '20 at 5:38
• 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. Jun 7 '20 at 12:13