Tutorial 43 - Creating a generic function II

A musical approach


One may apply to musical classes oper ators such as addition. In this case, adding a note to another note must be user defined. This will require to redefine a method starting from a user's generic function. In our case, we will start from our generic function myplus already defined in tutorial 42 and build new methods for NOTE and CHORD musical classes.


Functions used

x-append, sort., remove-dup, NOTE and CHORD.



New method for NOTES


We will define the addition operation for the NOTE class as adding up two notes. This will construct an interval. In order to do that we will use musical classes that you will find in the 'packages' folder on your workspace. The musical classes are found in the 'music -> score' subfolders.






If we open the NOTE class in the packages folder we will see these slots and their data type


The first slot is always 'self' and represents the object (class) itself. There we can access all data contained in the note. The self slot doesn't appear in the packaged representation because it is always present it most of the classes.


Further, there are some "hidden" slots that we cannot see in the graphical representation of these classes. In our example above it is the 'tie' slot. So, the extra outputs stand respectively as follows:










New method for CHORDS


We will now edit a new method for CHORDs . This method will concatenate two CHORDs into a single one, without any repretition of the same note and will sort all notes starting from the lowest pitch to the highest.





We will use this method as follows:



Two CHORDs factory are connected to myplus


You may notice that these two CHORDs have one common note: D sharp