Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- recievedData = [] # List to keep track of the latest keys that has been pressed.
- mididata = [[[144, 43, 100, 0], 13132],
- [[144, 36, 100, 0], 13152],
- [[144, 40, 100, 0], 13152]
- ]
- for event in mididata:
- # Above this line is just to emulate the mididata you are getting in. Only the recievedData = [] is needed in your code.
- # The line below this corelates to your line number 55 (data = event[0])
- data = event[0]
- note = data[1]
- time = event[1]
- # if theres is no data in recievedData, add the current note and timestamp
- if len(recievedData) == 0:
- recievedData.append([time,note])
- # else if there is less than 10 notes in the list add the current note IF the
- # timestamp does not differ "too much"
- elif len(recievedData) < 10:
- # check if the timestamp of this note is not later than 100ms after the previous.
- if not time > recievedData[-1][0] + 100: # [-1] = the last element, [0] = time of the last element.
- recievedData.append([time,note])
- else:
- # to much time has past, empty the recievedData list
- recievedData = []
- # if theres is more than 10 notes in the list its probably time to empty the list.
- else:
- recievedData = []
- print(recievedData)
- ################
- # Check the recievedData list to see if we can find any chords.
- if len(recievedData) > 2: #needs at least three notes to make a chord.
- templist = [] # a temporary list just to cointain the notes, and not timestamps.
- for data in recievedData:
- templist.append(data[1])
- templist.sort() # Make sure the keys are presented in ascending order.
- if templist[0] == 36 and templist[1] == 40 and templist[2] == 43:
- print("C major")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement