Overlaying music tracks on Mathematica and MIDI MIDI pedal events

All of the following applies to music / MIDI ( SoundNote objects), and not to selective sounds.

Unfortunately, Mathematica does not seem to be able to import MIDI. I am trying to create a simple MIDI ↔ CSV -based MIDI importer for single instrument files (piano focused).

What is the easiest way to overlay two Sound objects in Mathematica?

Show unites them; it does not overlap.

A not-too-simple approach is to parse Sound into SoundNote s, convert each SoundNote time SoundNote into {Tstart, Tend} format {Tstart, Tend} and assemble them into a new sound. Is there an easy way?

Second question:

Is there a simple way to handle pedal events in Mathematica , but it uses the internal sound representation and MIDI player, rather than playing MIDI through other means?

+7
source share
3 answers

1. Combination

To be able to overlay two Sound objects, there must be a total time. A simple SoundNote object has its own beginning of time and, therefore, using Sound in a list of them will only concatenate them and play them in sequential order. You will have to use absolute times for each to impose them. Thus, you can create MIDI music simultaneously with several instruments.

Here is a brief example (not polished) of an overlay. Bass notes play the piano, and high notes play the clarinet.

 tempo = 110; eighthNoteDuration = 60/tempo/2; trebleNotes = {"E5", "D#5", "E5", "D#5", "E5", "B", "D5", "C5", "A", None, "C", "E", "A", "B", None, "E", "G#", "B", "C5", None, "E", "E5", "D#5", "E5", "D#5", "E5", "B", "D5", "C5", "A", None, "C", "E", "A", "B", None, "E", "C5", "B", "A"}; trebleNoteDurations = {1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 4} eighthNoteDuration; trebleTimings = Partition[ Accumulate@Flatten @ Transpose@ {ConstantArray[0, Length@ #], #} &@ trebleNoteDurations, 2]; bassNotes = {None, None, "A2", "E3", "A3", None, None, "E3", "G#3", "B3", None, None, "A2", "E3", "A3", None, None, None, "A2", "E3", "A3", None, None, "E3", "G#3", "B3", None, None, "A2", "E3", "A3", None}; bassNoteDurations = {2, 6, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 6, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1} eighthNoteDuration; bassTimings = Partition[ Accumulate@Flatten @ Transpose@ {ConstantArray[0, Length@ #], #} &@ bassNoteDurations, 2]; Sound[Join[ SoundNote[#1, #2, "Piano"] & @@@ ({bassNotes, bassTimings}\[Transpose]), SoundNote[#1, #2, "Clarinet"] & @@@ ({trebleNotes, trebleTimings}\[Transpose])]] 

2. Pedal effects

As for your second question, I don't think you can reproduce the effects of the pedals using MIDI. The MIDI format is quite simple and actually does not transmit any sound. All the information he carries

  • Playing a note (pitch)
  • Note duration (tempo)
  • Trigger events to start and stop notes

The instrument you want to play depends entirely on your system and may play differently on different systems. Now, if you want to reproduce the effect of the pedal, you will need to write a function to break it into separate MIDI events, which are very similar to the actual effect of the pedal.

For example, you can change SoundNote or create a new function that, when passing the Sustain -> t option, prolongs the note for t seconds. You can make it more realistic and cut t seconds into smaller segments, and SoundVolume -> v as an additional option and v linearly / logarithmically decrease with each segment.

+7
source

Regarding your second question:

I previously reported on Mathematica's ability to connect to Nintendo Wiimote and Balanceboard using GlovePie and PPJoy, a virtual joystick that allows Mathematica to interact with your device, simulating a joystick (which MMA can read using ControllerState or ControllerInformation ). As far as I know, GlovePie also supports MIDI. You can try.

+2
source

You can combine or superimpose sound waves using convolution, as shown by the Mathematica code on this page:

http://www.copperthoughts.com/projects/convolution/

0
source