MIDIUtil icon indicating copy to clipboard operation
MIDIUtil copied to clipboard

ability to create more noticeably distinct notes

Open pyquest opened this issue 2 years ago • 1 comments

Hey I had an idea but don't know if it could be coded into the already existent code but here goes.

I think it would be cool if when writing the midi file in a series of degrees that there was a line of code that would set the length of each specific note to a desired uniform duration say, 3/16ths of a measure and quantize the beginning of each slice to start on some beat-- say, to the nearest quarter note-- so that there exists a brief period of silence between each note

The reason being is that this would allow for more notable distinct notes so that when using something like sonic visualiser it would be able to correctly read which notes were used to compile the audio.

More specifically what I am suggesting is the ability to control the four stages of musical envelope This being: attack, decay, sustain, and release (ADSR)

Attack is the time taken for initial run-up of level from nil to peak, beginning when the key is pressed. Decay is the time taken for the subsequent run down from the attack level to the designated sustain level. Sustain is the level during the main sequence of the sound's duration, until the key is released. Release is the time taken for the level to decay from the sustain level to zero after the key is released. While attack, decay, and release refer to time, sustain refers to level. https://en.wikipedia.org/wiki/Envelope_(music)

The reason for this request is that I am currently working on a project to turn written text into music and then turn that music back into text.

And as midi allows for a degree range of 0-127 I have found your script to be very suitable. also sonic visualiser is able to pick out the exact notes used in your script meaning that when I write a file (50,40,60) I can extract these same numbers in sonic visualiser using the polyphonic Transcription [university of alcante] Transform

However due to the various length of notes played (depending on pitch) and lack of a gap between notes. it is not always possible to pick out the exact notes and I believe that setting a fixed duration for each note with a fixed period of silence would make the notes more noticeable and thus allow sonic visualiser to pick out all the degrees that went into creating the file and allow for a successful decryption

pyquest avatar Feb 08 '22 20:02 pyquest

Hello again!

I think it would be cool if when writing the midi file in a series of degrees that there was a line of code that would set the length of each specific note to a desired uniform duration say, 3/16ths of a measure and quantize the beginning of each slice to start on some beat-- say, to the nearest quarter note-- so that there exists a brief period of silence between each note

You can achieve this with the code posted at #39 - just set the duration variable to 3/16. The built-in enumerate function is used to "quantize the beginning of each slice" by appending its index to the variable time. We can demonstrate this by doing the following modification to print the addNote call:

def addNotes(channel, degrees):
    for i, pitch in enumerate(degrees):
        if pitch >= 0:  # MIDI note numbers are greater than zero, so this
                        # allows skipping beats using negative degrees
            print(f'MyMIDI.addNote(track={track}, channel={channel}, pitch={pitch}, time={time + i}, duration={duration}, volume={volume})')

Here's the output:

MyMIDI.addNote(track=0, channel=0, pitch=60, time=0, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=0, pitch=62, time=1, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=0, pitch=64, time=2, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=0, pitch=65, time=3, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=0, pitch=67, time=4, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=0, pitch=69, time=5, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=0, pitch=71, time=6, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=0, pitch=72, time=7, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=1, pitch=72, time=0, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=1, pitch=71, time=1, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=1, pitch=69, time=2, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=1, pitch=67, time=3, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=1, pitch=65, time=4, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=1, pitch=64, time=5, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=1, pitch=62, time=6, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=1, pitch=60, time=7, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=2, pitch=50, time=0, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=2, pitch=50, time=2, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=2, pitch=50, time=4, duration=0.1875, volume=100)
MyMIDI.addNote(track=0, channel=2, pitch=50, time=6, duration=0.1875, volume=100)

Basically, silence is just a lack of noise, and is the result of time being left between notes - notes start playing at time beats, and stop playing at time+duration beats; ADSR isn't needed here. Hope this helps!

Edit: btw you seem to have opened a pull request instead of an issue - watch out for that next time!

introt avatar Apr 26 '22 10:04 introt