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.
x-append, sort., remove-dup, NOTE and CHORD.
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:
- self (the object itself)
- midic (an integer)
- vel (an integer)
- dur (an integer)
- chan (an integer)
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 first open a new method window and drag two CHORD classes onto both inputs as we have already done for the NOTE method
- We will connect the second slot (list of midics)of both inputs to x-append
- Connect x-append to sort. This will sort the newly concatenated list in an increasing order of midics
- Connect sort. to remove-dup in order to remove duplicates
- We will then connect the output of remove-dup to the second input <lmidic> of CHORD.
- The <self> output of CHORD is connected to the output of our new method
We will use this method as follows:
Two CHORDs factory are connected to myplus
- First CHORD:
- Second CHORD:
You may notice that these two CHORDs have one common note: D sharp
- The reulting CHORD in 'order' mode will be :