Skip to content

Commit

Permalink
aggiornamenti
Browse files Browse the repository at this point in the history
  • Loading branch information
lynerist committed May 10, 2021
1 parent 65c8998 commit bb5bbd0
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
outputAudio/
__pycache__
__pycache__
backups
15 changes: 10 additions & 5 deletions analisi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from functions import MidiInterface
import sys

song = "x_files"
song = "multiNoteOn"
trackNumber = 0
if len(sys.argv) > 1:
trackNumber = int(sys.argv[1])
trackNumber = sys.argv[1]

midi = MidiInterface(mido.MidiFile("midi/%s.mid"%song, clip=True))

Expand All @@ -18,6 +18,11 @@
print()


print("Messages of track %d:"%trackNumber)
for msg in midi.track(trackNumber):
print(msg)
if trackNumber == "a":
print("message from all tracks")
for msg in midi.allTracks:
print(msg)
else:
print("Messages of track %s:"%trackNumber)
for msg in midi.track(int(trackNumber)):
print(msg)
32 changes: 32 additions & 0 deletions createMidiWithMultipleNoteOn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#multi tracks in note on problem

import mido

midi = mido.MidiFile()
midi.ticks_per_beat = 92

track1 = mido.MidiTrack()

track1.append(mido.Message("note_on", note = 40, velocity = 100, time = 0))
track1.append(mido.Message("note_on", note = 70, velocity = 100, time = 0))
track1.append(mido.Message("note_on", note = 40, velocity = 80, time = 100))
track1.append(mido.Message("note_on", note = 70, velocity = 80, time = 0))
track1.append(mido.Message("note_on", note = 40, velocity = 50, time = 100))
track1.append(mido.Message("note_on", note = 70, velocity = 50, time = 0))
track1.append(mido.Message("note_on", note = 40, velocity = 0, time = 100))
track1.append(mido.Message("note_on", note = 70, velocity = 0, time = 0))

midi.tracks.append(track1)


track2 = mido.MidiTrack()

track2.append(mido.Message("note_on", note = 70, velocity = 100, time = 0))
track2.append(mido.Message("note_on", note = 70, velocity = 80, time = 50))
track2.append(mido.Message("note_on", note = 70, velocity = 50, time = 50))
track2.append(mido.Message("note_on", note = 70, velocity = 30, time = 50))
track2.append(mido.Message("note_on", note = 70, velocity = 0, time = 50))

midi.tracks.append(track2)

midi.save("midi/multiNoteOn.mid")
19 changes: 13 additions & 6 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ def pitchChange(sound, change):
adjuste the pitch by change semitones
"""
semitoneDistance = 2 ** (1/12)
#numpy interp1
#TODO guardare numpy interp1


speed = (semitoneDistance**change)
newAudio = sound._spawn(sound.raw_data, overrides={"frame_rate": int(sound.frame_rate * speed)})
return newAudio.set_frame_rate(sound.frame_rate)

def adjustLength(sound:AudioSegment, durationDesired):
#loop acceso spento
#ping pong
#attacco 12/15 ms
#rilascio 30/40 ms + fade out
#TODO loop acceso spento
#TODO ping pong
#TODO attacco 12/15 ms
#TODO rilascio 30/40 ms + fade out
"""
Adjust from the center cutting the samples or looping them
"""
Expand Down Expand Up @@ -125,13 +125,19 @@ def __init__ (self, note, countTicks, velocity):
self.startTime = countTicks
self.velocity = velocity

class BufferNoteOn:
def __init__ (self):
self._memory = dict()



class Instrument:
"""
interface to the audio samples of the instrument
"""
def __init__(self, instrument):
self.name = instrument
self.path = "instruments/%s/"%self.name
self.path = f"instruments/{self.name}/"
self.extension = ""

#leggo il range di note disponibili per lo strumento scelto
Expand All @@ -145,3 +151,4 @@ def __init__(self, instrument):
raise FileNotFoundError("Range file missing in instrument directory!\n")



Binary file added midi/One_piece.mid
Binary file not shown.
Binary file added midi/multiNoteOn.mid
Binary file not shown.
27 changes: 0 additions & 27 deletions preElaborazione/convertFromJustNoteOn.py

This file was deleted.

45 changes: 45 additions & 0 deletions prepareMidi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import mido
import os

song = "multiNoteOn"

midi = mido.MidiFile(f"midi/{song}.mid", clip=True)
print("Midi file:\n", midi, "\n")

newFile = mido.MidiFile()
newFile.ticks_per_beat = midi.ticks_per_beat

noteAlreadyOn = dict()

for track in midi.tracks:
newTrack = mido.MidiTrack()
newTrack.name = track.name
for msg in track:
if msg.type == "note_on":
if msg.velocity == 0:
msg = mido.Message("note_off", note = msg.note, time=msg.time)
elif noteAlreadyOn.get(msg.note):
newTrack.append(mido.Message("note_off", note = msg.note, time=msg.time))
newTrack.append(mido.Message("note_on", note = msg.note, velocity = msg.velocity, time = 0))
else:
newTrack.append(msg)
noteAlreadyOn[msg.note] = True


if msg.type == "note_off":
noteAlreadyOn[msg.note] = False
newTrack.append(msg)

newFile.tracks.append(newTrack)

#Se non esiste creo la directory dove collezionare i backups dei file midi
if not os.path.exists("backups"):
os.mkdir("backups")

midi.save(f"backups/{song}.mid")
newFile.save(f"midi/{song}.mid")


#TODO file di pre elaborazione


5 changes: 3 additions & 2 deletions sintesi.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import mido
from functions import *

song = "evangelion"
instrument = "violin"
song = "multiNoteOn"
instrument = "trumpet"

try:
instrument = Instrument(instrument)
Expand Down Expand Up @@ -39,6 +39,7 @@
if msg.type == "note_on":
countTicks += msg.time # Clock
noteOnCollection[msg.note] = Note(msg.note, countTicks, msg.velocity)


elif msg.type == "note_off":
countTicks += msg.time # Clock
Expand Down

0 comments on commit bb5bbd0

Please sign in to comment.