Initial Commit

This commit is contained in:
2018-05-19 02:20:19 +02:00
commit 8621248968
6554 changed files with 1121559 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
import os
for x in range(1,128):
os.system('python Interpreter.py "Bpm(80)[Inst(' + str(x) + ')|:3G#4q Bb4s G#4s Bb4s p1s Eb4q p1q|]*(1)" "lead' + str(x) +'"')

View File

@@ -0,0 +1,16 @@
import pymongo
from pymongo import MongoClient
import json
client = MongoClient('localhost', 27017)
db = client.tweets
file_obj = open('tweets.json', 'r')
print(file_obj)
raw_data = file_obj.read()
temp = json.loads(raw_data)
post = []
posts = db.posts
for tweet in temp['tweets']:
#post.append(tweet)
db.tweets.insert(tweet)
open("tweets.json", 'w').close()

View File

View File

@@ -0,0 +1,35 @@
import MidiGenerator as m
import sys
import os
'''
m.MakeMidiFile("Piano", 280, 1)
m.AddChord( [No(F, 4), No(C, 5)], 1, 100)
m.AddChord( [No(F, 4), No(C, 5)], 1, 100)
m.AddChord( [No(F, 4), No(C, 5)], 1, 100)
m.AddChord( [No(F, 4), No(C, 5)], 1, 100)
m.AddPause(1)
m.AddChord( [No(Eb, 4), No(C, 4), No(Ab, 4)], 2, 100)
m.AddChord( [No(D, 4),No(F, 4),No(Bb, 4)], 2, 100)
m.AddChord( [No(E, 4), No(C, 5)], 1, 100)
m.AddPause(1)
m.AddChord( [No(D, 4), No(Bb, 4)], 1, 100)
m.AddChord( [No(E, 4), No(C, 5)], 4, 100)
m.AddPause(6)
m.ExportMidi("FFVictoryTheme")
'''
m.MakeMidiFile("Piano", 280, 1)
m.AddChord(['F4' ,'C5'], 1, 100)
m.AddChord(['F4' ,'C5'], 1, 100)
m.AddChord(['F4' ,'C5'], 1, 100)
m.AddChord(['F4' ,'C5'], 1, 100)
m.AddPause(1)
m.AddChord( ['Eb4', 'C4', 'Ab4'], 2, 100)
m.AddChord( ['D4','F4','Bb4'], 2, 100)
m.AddChord( ['E4', 'C5'], 1, 100)
m.AddPause(1)
m.AddChord( ['D4', 'Bb4'], 1, 100)
m.AddChord( ['E4', 'C5'], 4, 100)
m.AddPause(6)
m.AddNote('Solb6',4,100)
m.ExportMidi("FFVictoryTheme")

View File

@@ -0,0 +1,392 @@
import sys
import schedule
import os
import MidiGenerator as m
import time
import json
from os import listdir
from os.path import isfile, join
#vars
#notes first letters
nts = {"D", "R", "M", "F", "S", "L", "S", "T", "C", "E", "G", "A", "B"}
times = {"O", "o", "q", "t", "s"}
Modifiers = {"(", ")", "|", ":"}
speshNts = {"D", "F"}
eu = {"R", "M", "S", "L", "T", "S"}
us = {"C", "E", "G", "A", "B"}
times = {'O' : 4, 'o' : 2, 'q' : 1, 't' : .5, 's' : .25}
channels = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,'A':10,'B':11,'C':12,'D':13,'E':14,'F':15}
noteMods = {"b", "#"}
filetype = None
'| B2t E3t (B3 F4)q pt D4t D3t A3t D4t E4t E3t B4t pt D5t |'
song = '| E4q G#4q B4q pq | ( E4 G#4 B4 )o po |'
ConvertionNotPossible = False
bpm = 140
#/home/beppe/Documents/Python/proj/1718JrpiRadio/PythonCode/Midi/
songPath = "/songs/"
nonExistantNotes = {"D#", "Cb", "E#", "Fb", "Si#", "Ti#", "Dob", "Mi#", "Fab"}
#Methods
instrument = 0
def GetNextCharThing(pos, strg):
global ConvertionNotPossible
temp = strg[pos]
if temp in nts:
note = GetNoteStr(pos, strg)
timing = strg[pos+len(note)]
try:
m.AddNote(note, times[timing], 100)
except:
ConvertionNotPossible = True
print(str(sys.exc_info()[0]) + " ERROR HAPPENED AT ADDNOTE, ConvertionNotPossible = " + str(ConvertionNotPossible))
return pos+len(note)+1
elif temp in Modifiers:
if temp == "|":
return pos+1
elif temp == ":":
chan = strg[pos+1]
if chan in channels:
try:
m.Selected_channel = channels[chan]
m.ChangeInstrument(instrument)
except:
ConvertionNotPossible = True
print(str(sys.exc_info()[0]) + " ERROR HAPPENED AT CHANGEINSTRUMENT, ConvertionNotPossible = " + str(ConvertionNotPossible))
return pos+2
elif temp == "(":
charNr = pos +1
notes = []
while True:
if strg[charNr] in nts:
tempNote = GetNoteStr(charNr, strg)
notes.append(tempNote)
charNr = charNr + len(tempNote)
elif strg[charNr] == ")":
timing = strg[charNr+1]
try:
m.AddChord(notes, times[timing], 100)
except:
ConvertionNotPossible = True
print(str(sys.exc_info()[0]) + " ERROR HAPPENED AT ADDCHORD, ConvertionNotPossible = " + str(ConvertionNotPossible))
return charNr+1
break
elif strg[charNr] == "|":
charNr = charNr+1
elif temp in times:
return pos+1
elif temp == 'p':
amount = strg[pos+1]
timing = strg[pos+2]
try:
m.AddPause(amount, times[timing])
except:
ConvertionNotPossible = True
print(str(sys.exc_info()[0]) + " ERROR HAPPENED AT PAUSES, ConvertionNotPossible = " + str(ConvertionNotPossible))
return pos+2
else:
ConvertionNotPossible = True
return pos+1
def GetNoteStr(pos, strg):
temp = strg[pos]
if temp in nts:
if temp in speshNts:
if temp == "D":
if strg[pos+1] == "o":
if strg[pos+2] in noteMods:
note = strg[pos:pos+3]
octv = strg[pos+3]
return note+octv
else:
note = strg[pos:pos+2]
octv = strg[pos+2]
return note+octv
else:
if strg[pos+1] in noteMods:
note = strg[pos:pos+2]
octv = strg[pos+2]
return note+octv
else:
note = strg[pos]
octv = strg[pos+1]
return note+octv
else:
if strg[pos+1] == "a":
if strg[pos+2] in noteMods:
note = strg[pos:pos+3]
octv = strg[pos+3]
return note+octv
else:
note = strg[pos:pos+2]
octv = strg[pos+2]
return note+octv
else:
if strg[pos+1] in noteMods:
note = strg[pos:pos+2]
octv = strg[pos+2]
return note+octv
else:
note = strg[pos]
octv = strg[pos+1]
return note+octv
elif temp in eu:
if temp == "S":
if strg[pos+1] == "o":
if strg[pos+3] in noteMods:
note = strg[pos:pos+4]
octv = strg[pos+4]
return note+octv
else:
note = strg[pos:pos+3]
octv = strg[pos+3]
return note+octv
else:
if strg[pos+2] in noteMods:
note = strg[pos:pos+3]
octv = strg[pos+3]
return note+octv
else:
note = strg[pos:pos+2]
octv = strg[pos+2]
return note+octv
else:
if strg[pos+2] in noteMods:
note = strg[pos:pos+3]
octv = strg[pos+3]
return note+octv
else:
note = strg[pos:pos+2]
octv = strg[pos+2]
return note+octv
elif temp in us:
if strg[pos+1] in noteMods:
note = strg[pos:pos+2]
octv = strg[pos+2]
return note+octv
else:
note = strg[pos]
octv = strg[pos+1]
return note+octv
else:
return None
else:
return None
def writeSong(sng, title, bpm = 140, inst=1):
global songPath
m.MakeMidiFile(bpm, 16, 1)
currentpos = sng.find('|')
global instrument
global ConvertionNotPossible
if (instrument > 0):
m.ChangeInstrument(instrument)
else:
instrument = 1
while currentpos < len(sng):
currentpos = GetNextCharThing(currentpos, sng)
if ConvertionNotPossible:
break
if not ConvertionNotPossible:
m.ExportMidi(songPath + title)
else:
print("NOTABLETOWRITETRACK")
return True
def writeSongTracked(sngTracks, title, bpm=140, inst=1):
m.MakeMidiFile(bpm, 16, len(sngTracks)+1)
tracknr = 1
global ConvertionNotPossible, songPath
for track in sngTracks:
currentpos = track.find('|')
m.ChangeTrack(tracknr)
global instrument
InstrumentChk(track)
if (instrument > 0):
m.ChangeInstrument(instrument)
else:
instrument = 1
m.ChangeInstrument(instrument)
while currentpos < len(track):
currentpos = GetNextCharThing(currentpos, track)
if ConvertionNotPossible:
break
print (ConvertionNotPossible)
tracknr = tracknr +1
print (ConvertionNotPossible)
print (ConvertionNotPossible)
if not ConvertionNotPossible:
m.ExportMidi(songPath + title)
else:
print("NOTABLETOWRITETRACK")
m.ExportMidi(songPath + title)
return
def checkText(txt):
if txt.find('|') == -1:
return True
if any(Noot in txt for Noot in nonExistantNotes):
return True
return False
def ConvertFile(CONVERTABLEFILE):
title = ""
song = ""
global ConvertionNotPossible
ConvertionNotPossible = False
file = str(CONVERTABLEFILE)
file_extension = file[len(file)-5:]
if file_extension == '.json':
content = ""
with open(CONVERTABLEFILE, 'r') as contentfile:
content = contentfile.read()
print(content)
temp = json.loads(content)
for tweet in temp['tweets']:
song = tweet['text']
song = song.replace(" ", "")
ConvertionNotPossible = checkText(song)
title = tweet['UserName'] + " id_" + str(tweet['id'])
if ConvertionNotPossible == False:
writeSong(song, title)
tweet['location'] = 'songs/' + title + '.mid'
tweet['success'] = "yes"
with open('tweets.json', "w") as outfile:
json.dump(temp, outfile)
return
else:
title = os.path.basename(file)
with open(file, 'r') as files:
song = files.readline()
song = song.replace(" ", "")
firstBar = song.find('|')
checkText(song)
writeSong(song, title)
if ConvertionNotPossible:
with open(Directory+"/FailedLog", "a") as files:
files.write("song " + title + " has failed to initialise.... \n")
def is_number(s):
try:
int(s)
return True
except ValueError:
return False
def checkItems(path):
items = os.path.listdir(path)
for item in items:
ConvertFile(item)
return True
def checkTempo(strb):
global bpm
if strb.find("Bpm(") > -1:
temp = strb[strb.find("Bpm(")+4:strb.find(")")]
if is_number(temp):
bpm = int(temp)
else:
bpm = 140
return
def ConvertText(txt, ttl=time.strftime("%d_%m_%y_%H_%M_%S")):
song = txt
title = ttl
tracked = False
song = song.replace(" ", "")
checkTempo(song)
global ConvertionNotPossible
if "[" in song:
song = song.split("[")
tracked = True
if tracked:
songs = []
for track in song:
checkText(track)
if "Inst(" in track:
instStr = track[track.find("Inst("):track.find(")")+1]
else:
instStr = ""
testnaam = track[track.find("]")+3:len(track)-1]
temptrs = track[track.find("|"):track.find("]")]
if is_number(testnaam):
songs.append(instStr + temptrs*int(testnaam))
writeSongTracked(songs, title, bpm)
else:
InstrumentChk(song)
checkText(song)
writeSong(song, title, bpm)
if ConvertionNotPossible:
print('failed to export as song')
else:
print('normally it\'s exported now under the title of ' + title+'.mid')
return True
def InstrumentChk(txt):
global instrument
Inst = txt
if "Inst" in txt:
Inst = Inst[Inst.find("Inst(")+5:Inst.find(")")]
if is_number(Inst):
if int(Inst) < 129:
instrument = int(Inst)
else:
instrument = 0
else:
if Inst in m.DictOfInstruments:
instrument = m.DictOfInstruments[Inst]
else:
instrument = 0
def is_convertabletxt(txt):
if txt.find("|") > -1:
return True
return False
def startupRoutine():
if len(sys.argv) > 1:
if os.path.isdir(sys.argv[1]):
checkItems(sys.argv[1])
else:
if is_convertabletxt(sys.argv[1]):
if len(sys.argv) > 2:
ConvertText(sys.argv[1], sys.argv[2])
else:
ConvertText(sys.argv[1])
sys.exit()
if os.path.isfile(sys.argv[1]):
ConvertFile(sys.argv[1])
sys.exit()
print("no valid argument was found\nDo you want to continue? (y/n)")
char = input()
if char == 'y':
print('\nPlease enter the title of the string you want to convert,\nif you don\'t want to give it a name, then leave it blank and it will get a timestamp as the title.')
title = input()
print('\nPlease enter the content of the string you want to convert')
content = input()
print('\nConverting')
if(is_convertabletxt(content)):
if(title==""):
ConvertText(content)
else:
ConvertText(content, title)
else:
print('\nthe text you entered is non convertable\nPress enter to continue...')
input()
sys.exit()
else:
sys.exit()
startupRoutine()

View File

@@ -0,0 +1,352 @@
from midiutil.MidiFile3 import MIDIFile
import random
import sys
import os
#--Variables--
#MIDI Variables
Selected_channel = 0
Selected_track = 0
Time_Constant = 0
Miditrack = MIDIFile(0)
#notes variables. these are pitches of the notes, add 12 to them for every octave you wanna go up
DictOfNotes = {'C' : 0, 'Do' : 0, 'Do#' : 1, 'C#' : 1, 'Reb' : 1, 'Db' : 1, 'Re' : 2, 'D' : 2, 'D#' : 3, 'Re#' : 3, 'Mib' : 3, 'Eb' : 3, 'Mi' : 4, 'E' : 4, 'F' : 5, 'Fa' : 5, 'F#' : 6,'Fa#' : 6, 'Solb':6, 'Gb' : 6, 'Sol':7, 'G' : 7, 'Sol#' : 8, 'G#' : 8, 'Lab' : 8, 'Ab' : 8,'La':9, 'A' : 9,'La#' : 10, 'A#' : 10, 'Bb' : 10,'Sib': 10, 'Tib': 10, 'B' : 11, 'Si':11, 'Ti':11}
C = 0
Db = 1
D = 2
Eb = 3
E = 4
F = 5
Gb = 6
G = 7
Ab = 8
A = 9
Bb = 10
B = 11
#Instrument Variables
DictOfInstruments = {'Piano' : 1, 'Bright_Piano' : 2,'Electric_Grand_Piano' : 3,'Honkytonk_Piano' : 4,'Electric_Piano' : 5,'Electric_Piano_2' : 6,'Harpsichord' : 7,'Clavinet' : 8,'Celesta' : 9,'Glockenspiel' : 10,'Music_Box' : 11,'Vibraphone' : 12,'Marimba' : 13,'Xylophone' : 14,'Tubular_Bells' : 15,'Dulcimer' : 16,'Drawbar_Organ' : 17,'Percussive_Organ' : 18,'Rock_Organ' : 19,'Church_Organ' : 20,'Reed_Organ' : 21,'Accordion' : 22,'Harmonica' : 23,'Tango_Accordion' : 24,'Acoustic_Guitar_nylon' : 25,'Acoustic_Guitar_steel' : 26,'Electric_Guitar_jazz' : 27,'Electric_Guitar_clean' : 28,'Electric_Guitar_muted' : 29,'Overdriven_Guitar' : 30,'Distortion_Guitar' : 31,'Guitar_Harmonics' : 49,'Acoustic_Bass' : 33,'Electric_Bass_finger' : 34,'Electric_Bass_pick' : 35,'Fretless_Bass' : 36,'Slap_Bass' : 37,'Slap_Bass_2' : 38,'Synth_Bass' : 39,'Synth_Bass_2' : 40,'Violin' : 41,'Viola' : 42,'Cello' : 43,'Contrabass' : 44,'Tremolo_Strings' : 45,'Pizzicato_Strings' : 46,'Orchestral_Harp' : 47,'Timpani' : 48,'String_Ensemble' : 49,'String_Ensemble_2' : 50,'Synth_Strings' : 51,'Synth_Strings_2' : 52,'Choir_Aahs' : 53,'Voice_Oohs' : 54,'Synth_Choir' : 55,'Orchestra_Hit' : 56,'Trumpet' : 57,'Trombone' : 58,'Tuba' : 59,'Muted_Trumpet' : 60,'French_Horn' : 61,'Brass_Section' : 62,'Synth_Brass' : 63,'Synth_Brass_2' : 64,'Soprano_Sax' : 65,'Alto_Sax' : 66,'Tenor_Sax' : 67,'Baritone_Sax' : 68,'Oboe' : 69,'English_Horn' : 70,'Bassoon' : 71,'Clarinet' : 72,'Piccolo' : 73,'Flute' : 74,'Recorder' : 75,'Pan_Flute' : 76,'Blown_bottle' : 77,'Shakuhachi' : 78,'Whistle' : 79,'Ocarina' : 80,'Synth_Lead_square' : 81,'Synth_Lead_sawtooth' : 82,'Synth_Lead_calliope' : 83,'Synth_Lead_chiff' : 84,'Synth_Lead_charang' : 85,'Synth_Lead_voice' : 86,'Synth_Lead_fifths' : 87,'Synth_Lead_bass_and_lead' : 88,'Synth_Pad_new_age' : 89,'Synth_Pad_warm' : 90,'Synth_Pad_polysynth' : 91,'Synth_Pad_choir' : 92,'Synth_Pad_bowed' : 93,'Synth_Pad_metallic' : 94,'Synth_Pad_halo' : 95,'Synth_Pad_sweep' : 96,'Synth_FX_rain' : 97,'Synth_FX_soundtrack' : 98,'Synth_FX_crystal' : 99,'Synth_FX_atmosphere' : 100,'Synth_FX_brightness' : 101,'Synth_FX_goblins' : 102,'Synth_FX_echoes' : 103,'Synth_FX_scifi' : 104,'Sitar' : 105,'Banjo' : 106,'Shamisen' : 107,'Koto' : 108,'Kalimba' : 109,'Bagpipe' : 110,'Fiddle' : 111,'Shanai' : 112,'Tinkle_Bell' : 113,'Agogo' : 114,'Steel_Drums' : 115,'Woodblock' : 116,'Taiko_Drum' : 117,'Melodic_Tom' : 118,'Synth_Drum' : 119,'Reverse_Cymbal' : 120,'Guitar_Fret_Noise' : 121,'Breath_Noise' : 122,'Seashore' : 123,'Bird_Tweet' : 124,'Telephone_Ring' : 125,'Helicopter' : 126,'Applause' : 127,'Gunshot' : 128}
#Pianos
Piano = 1
Bright_Piano = 2
Electric_Grand_Piano = 3
Honkytonk_Piano = 4
Electric_Piano = 5
Electric_Piano_2 = 6
Harpsichord = 7
Clavinet = 8
#Chromatic_Percussion
Celesta = 9
Glockenspiel = 10
Music_Box = 11
Vibraphone = 12
Marimba = 13
Xylophone = 14
Tubular_Bells = 15
Dulcimer = 16
#Organ
Drawbar_Organ = 17
Percussive_Organ = 18
Rock_Organ = 19
Church_Organ = 20
Reed_Organ = 21
Accordion = 22
Harmonica = 23
Tango_Accordion = 24
#Guitar
Acoustic_Guitar_nylon = 25
Acoustic_Guitar_steel = 26
Electric_Guitar_jazz = 27
Electric_Guitar_clean = 28
Electric_Guitar_muted = 29
Overdriven_Guitar = 30
Distortion_Guitar = 31
Guitar_Harmonics = 49
#Bass
Acoustic_Bass = 33
Electric_Bass_finger = 34
Electric_Bass_pick = 35
Fretless_Bass = 36
Slap_Bass = 37
Slap_Bass_2 = 38
Synth_Bass = 39
Synth_Bass_2 = 40
#Strings
Violin = 41
Viola = 42
Cello = 43
Contrabass = 44
Tremolo_Strings = 45
Pizzicato_Strings = 46
Orchestral_Harp = 47
Timpani = 48
#Ensemble
String_Ensemble = 49
String_Ensemble_2 = 50
Synth_Strings = 51
Synth_Strings_2 = 52
Choir_Aahs = 53
Voice_Oohs = 54
Synth_Choir = 55
Orchestra_Hit = 56
#Brass
Trumpet = 57
Trombone = 58
Tuba = 59
Muted_Trumpet = 60
French_Horn = 61
Brass_Section = 62
Synth_Brass = 63
Synth_Brass_2 = 64
#Reed
Soprano_Sax = 65
Alto_Sax = 66
Tenor_Sax = 67
Baritone_Sax = 68
Oboe = 69
English_Horn = 70
Bassoon = 71
Clarinet = 72
#Pipe
Piccolo = 73
Flute = 74
Recorder = 75
Pan_Flute = 76
Blown_bottle = 77
Shakuhachi = 78
Whistle = 79
Ocarina = 80
#Synth_Lead
Synth_Lead_square = 81
Synth_Lead_sawtooth = 82
Synth_Lead_calliope = 83
Synth_Lead_chiff = 84
Synth_Lead_charang = 85
Synth_Lead_voice = 86
Synth_Lead_fifths = 87
Synth_Lead_bass_and_lead = 88
#Synth_Pad
Synth_Pad_new_age = 89
Synth_Pad_warm = 90
Synth_Pad_polysynth = 91
Synth_Pad_choir = 92
Synth_Pad_bowed = 93
Synth_Pad_metallic = 94
Synth_Pad_halo = 95
Synth_Pad_sweep = 96
#Synth_Effects
Synth_FX_rain = 97
Synth_FX_soundtrack = 98
Synth_FX_crystal = 99
Synth_FX_atmosphere = 100
Synth_FX_brightness = 101
Synth_FX_goblins = 102
Synth_FX_echoes = 103
Synth_FX_scifi = 104
#Ethnic
Sitar = 105
Banjo = 106
Shamisen = 107
Koto = 108
Kalimba = 109
Bagpipe = 110
Fiddle = 111
Shanai = 112
#Percussive
Tinkle_Bell = 113
Agogo = 114
Steel_Drums = 115
Woodblock = 116
Taiko_Drum = 117
Melodic_Tom = 118
Synth_Drum = 119
Reverse_Cymbal = 120
#Sound_effects
Guitar_Fret_Noise = 121
Breath_Noise = 122
Seashore = 123
Bird_Tweet = 124
Telephone_Ring = 125
Helicopter = 126
Applause = 127
Gunshot = 128
#--Functions--
#creates a midi file with the wanted amount of tracks, at the tempo and wanted amount of channels.
#these will always be in 4/4ths, since like 90% of music is in 4/4ths anyway it doesn't matter, and if we want, we can make it any multiple of the 4/4ths time since we can just increase the tempo, or take multiple bars and emulate them being one bar.
def MakeMidiFile(Tempo, Channels, Tracks = 16):
global Selected_channel
global Selected_track
global Time_Constant
global Miditrack
Time_Constant = 0
Selected_track = 0
Selected_channel = 0
Miditrack = MIDIFile(Tracks)
for x in range(0,Tracks):
trcknm = "track " + str(x)
Miditrack.addTrackName(x, Time_Constant, trcknm)
Miditrack.addTempo(x, Time_Constant, Tempo)
return
#changes note to the octave you want
def No( note, octave ):
temp = note + (12 * octave)
return int(note + (12 * octave))
def NoPrs( string ):
if len(string) > 3:
octNr = string[-1]
noteNr = DictOfNotes[string[0:-1]]
elif len(string) > 2 :
octNr = string[-1]
noteNr = DictOfNotes[string[0:-1]]
else:
octNr = string[-1]
noteNr = DictOfNotes[string[0]]
return No(noteNr, int(octNr))
#adds a single note to the track and sets the time_constant further
def AddNote( note, duration, volume ):
global Selected_channel
global Selected_track
global Time_Constant
global Miditrack
Miditrack.addNote(Selected_track, Selected_channel, NoPrs(note), Time_Constant, duration, volume)
Time_Constant += duration
return
#adds multiple notes to the track and sets the time_constant further
def AddChord( notes, duration, volume ):
global Selected_channel
global Selected_track
global Time_Constant
global Miditrack
for note in notes:
nr = NoPrs(note)
Miditrack.addNote(Selected_track, Selected_channel, nr, Time_Constant, duration, volume)
Time_Constant += duration
return
#adds a pause in the track
def AddPause( times, duration ):
if (is_number(times)):
for x in range (0, int(times)):
AddNote('C0', duration, 0)
else:
AddNote('C0', duration, 0)
return
#generates the .mid and writes it to given name
def ExportMidi(FileName):
global Miditrack
binfile = open(FileName+".mid", 'wb')
Miditrack.writeFile(binfile)
binfile.close()
return
def ChangeInstrument(InstrumentNr = 1, Channel = None, Track = None):
global Selected_channel
global Selected_track
global Time_Constant
global Miditrack
if Channel is None:
Channel = Selected_channel
if Track == None:
Track = Selected_track
if InstrumentNr in DictOfInstruments:
InstrumentNr = DictOfInstruments[InstrumentNr]
elif is_number(InstrumentNr):
InstrumentNr = int(InstrumentNr)
else:
InstrumentNr = 1
Miditrack.addProgramChange(Track, Channel, Time_Constant, InstrumentNr)
return
def ChangeTrack(tracknr):
global Selected_channel
global Selected_track
global Time_Constant
global Miditrack
Time_Constant = 0
Selected_track = tracknr
if Selected_track == None or Selected_track < 1:
Selected_track = 1
return
def is_number(s):
try:
int(s)
return True
except ValueError:
return False

Binary file not shown.

View File

@@ -0,0 +1,231 @@
# Syntax
## Types of notes
The usage of european (Do Re Mi Fa Sol La Si/Ti) notes are allowed and will work just as well as american notation (A B C D E F G). After that we signify if the note is flat (b) or sharp (#) and then we put the octave we want the note to be on.
## Pauses
a "p" sign signifies a pause, it works the same as a normal note, but is just silent. ex:
"pq" is a quarter note pause
## Timing
Timing was a little harder to do in a user friendly manner, however. this is how the script understands length of notes.
O is a whole note
o is a half note
q is a quarter note
t is an eight note
s is a sixteenth note
you would add these after your notes to signify how long the note should last
## Instruments
Right now i have it set that you have to set your instrument before you start your song part(?). The syntax for this is Inst($$$), with $$$ representing the name of one of the instruments or the instrument number. these are the program change event values that is used in General Midi (GM) at the end of this readme i will include a list of all the numbers with their respective instruments
## Tracks
Right now this feature is not yet fully implimented because of the way syntax works. I would really like to implement it, but damn is it hard to find an easy way to put this in text form.
## Channels and the implication of not having access to channel 10 at this stage
At this point i'm having trouble implementing this concept of channels. Normally you would think this isn't that bad, because you can easily implement tracks. However, in GM there is a channel reserved for percussion which makes it a lot easyer to create percussion in a song. Right now as i'm trying to implement tracks i could create percussion by assigning an instrument to a certain track and playing my notes by that track and the sample of the drump to a pitch. This however is not very handy. so i would much rather create a syntax for the 10th midi channel so that i could have access to create a more comprehensive track
## Examples
example:
| E4q G#4q B4q pq |
this would result in the notes E G# and B being played in the 4th octave all for 1/4th of a bar, and then there is a 1/4th of a bar of rest.
chords are created using the ( ) signs. you can put multiple notes inside of the () without marking their timing, and then mark the time after the chord. example:
| ( E4 G#4 B4 )o po |
this would result in half a bar of the chord e-major being played, and then half a bar of pause.
### Prototype Examples
Here i'm going to put the examples of ways to syntax this shit so that i can actually code towards this syntax. Pro's from going at it from this side is that creating a syntax from this way would make it a lot more user friendly (or at least friendly for me to use) because i think ab out the syntax first and then the code behind deserializing(?) it.
#### Channels
so in the end i have decided to go with tracks at a later time and focus on channels for now.
taking our basic note note note pause chord pause progression:
| E4q G#4q B4q pq | ( E4 G#4 B4 )o po |
##### Formula 1
|:1 E4q G#4q B4q pq |:2 ( E4 G#4 B4 )o po |
the idea being that the number would represent the channel of the track, problem with this being that there are more then 10 channels, so even using 0 as a channel, we would get into double digits. This brings me to the next version:
##### formula 2
|:1 E4q G#4q B4q pq |:B ( E4 G#4 B4 )o po |
It is the same concept as the one above, but it uses the hexadecimal system. so :1 would mean channel 2, :0 would become channel 1 and :B would become channel 12 this way we can use all 16 channels with a minimal amount of space used and it helps a lot during interpretation. the cost of this being that it makes it less ux friendly. but when you're at the point of using channels, it doesn't matter anymore. channel 9 would be percussion so the only reason to use channels a b c d e and f would be for even more instruments and at that point, why not use a daw. (Digital audio workstation)
#### tracks
the concept behind tracks right now will be to get notes to play at the same time. hopefully we'll be able to make tracks repeat at the end, but thats gonna be kindof hard.
syntax possibilities
##### formula 1
`[|:1 E4q G#4q B4q pq |]*(3)[Inst(44)|:2 ( E4 G#4 B4 )o po |]*(5)`
this is the forumla i eventually ended upon, instrument changes still work, this reps the first bar 3 times and during that reps the last bar 5 times
# Channel 10 (9)
In general midi channel number 9 is used as a channel exclusively for percussion, certain notes create a sound, see the list of what notes make what sound below (at a later date)
# Instrument List
## Piano
1 Piano
2 Bright_Piano
3 Electric_Grand_Piano
4 Honkytonk_Piano
5 Electric_Piano
6 Electric_Piano_2
7 Harpsichord
8 Clavinet
## Chromatic Percussion
9 Celesta
10 Glockenspiel
11 Music_Box
12 Vibraphone
13 Marimba
14 Xylophone
15 Tubular_Bells
16 Dulcimer
## Organ
17 Drawbar_Organ
18 Percussive_Organ
19 Rock_Organ
20 Church_Organ
21 Reed_Organ
22 Accordion
23 Harmonica
24 Tango_Accordion
## Guitar
25 Acoustic_Guitar_nylon
26 Acoustic_Guitar_steel
27 Electric_Guitar_jazz
28 Electric_Guitar_clean
29 Electric_Guitar_muted
30 Overdriven_Guitar
31 Distortion_Guitar
32 Guitar_Harmonics
## Bass
33 Acoustic_Bass
34 Electric_Bass_finger
35 Electric_Bass_pick
36 Fretless_Bass
37 Slap_Bass
38 Slap_Bass_2
39 Synth_Bass
40 Synth_Bass_2
## Strings
41 Violin
42 Viola
43 Cello
44 Contrabass
45 Tremolo_Strings
46 Pizzicato_Strings
47 Orchestral_Harp
48 Timpani
## Ensemble
49 String_Ensemble
50 SString_Ensemble_2
51 Synth_Strings
52 Synth_Strings_2
53 Choir_Aahs
54 Voice_Oohs
55 Synth_Choir
56 Orchestra_Hit
## Brass
57 Trumpet
58 Trombone
59 Tuba
60 Muted_Trumpet
61 French_Horn
62 Brass_Section
63 Synth_Brass
64 Synth_Brass_2
## Reed
65 Soprano_Sax
66 Alto_Sax
67 Tenor_Sax
68 Baritone_Sax
69 Oboe
70 English_Horn
71 Bassoon
72 Clarinet
## Pipe
73 Piccolo
74 Flute
75 Recorder
76 Pan_Flute
77 Blown_bottle
78 Shakuhachi
79 Whistle
80 Ocarina
## Synth Lead
81 Synth_Lead_square
82 Synth_Lead_sawtooth
83 Synth_Lead_calliope
84 Synth_Lead_chiff
85 Synth_Lead_charang
86 Synth_Lead_voice
87 Synth_Lead_fifths
88 Synth_Lead_bass_and_lead
## Synth Pad
89 Synth_Pad_new_age
90 Synth_Pad_warm
91 Synth_Pad_polysynth
92 Synth_Pad_choir
93 Synth_Pad_bowed
94 Synth_Pad_metallic
95 Synth_Pad_halo
96 Synth_Pad_sweep
## Synth Effects
97 Synth_FX_rain
98 Synth_FX_soundtrack
99 Synth_FX_crystal
100 Synth_FX_atmosphere
101 Synth_FX_brightness
102 Synth_FX_goblins
103 Synth_FX_echoes
104 Synth_FX_scifi
## Ethnic
105 Sitar
106 Banjo
107 Shamisen
108 Koto
109 Kalimba
110 Bagpipe
111 Fiddle
112 Shanai
## Percussive
113 Tinkle_Bell
114 Agogo
115 Steel_Drums
116 Woodblock
117 Taiko_Drum
118 Melodic_Tom
119 Synth_Drum
120 Reverse_Cymbal
## Sound effects
121 Guitar_Fret_Noise
122 Breath_Noise
123 Seashore
124 Bird_Tweet
125 Telephone_Ring
126 Helicopter
127 Applause
128 Gunshot

View File

@@ -0,0 +1,31 @@
import os
import sys
import schedule
import MidiGenerator as m
import time
from os import listdir
from os.path import isfile, join
import twitter
import json
import requests
from multiprocessing import Process
mongodbPath = 'c:/MongoDb/bin/mongod'
jsonPath = 'tweets.json'
def runLoop():
os.system('python TwitterGetExample.py')
os.system('python Interpreter.py ' + jsonPath)
time.sleep(30)
os.system('python DbUpdate.py')
schedule.every(1).minutes.do(runLoop)
#os.system(mongodbPath) this doesn't finish, so other programs won't run
runLoop()
while 1:
schedule.run_pending()
time.sleep(1)

View File

@@ -0,0 +1,23 @@
bassnote:
Bpm(80)[|:1p1qD#2qp1qBb2qp1qD#2qp1qBb2qp1qD#2qp1qBb2qp1qD#2qp1qB1q|]
BassChords:
Mi#SibRe#
"Bpm(80)[|:2D#2q(F#3Bb3D#3)sp1s(F#3Bb3D#3)tBb2q(F#3Bb3D#3)qD#2q(F#3Bb3D#3)sp1s(F#3Bb3D#3)tBb2q(F#3Bb3D#3)qD#2q(F#3Bb3D#3)sp1s(F#3Bb3D#3)tBb2q(F#3Bb3D#3)qD#2q(F#3Bb3D#3)sp1s(F#3Bb3D#3)tB2q(G#3B3E3)q|]*(3)[|:9(F#3C3)tF#3t(E3F#3)tF#3t|]*(20)[Inst(8)|:3|]*(1)"
hi hats 8th F3#
[|:9(F#3C3F#4)t(F#3F#4)t(E3F#3F#4)t(F#3F#4)t(C3F#3F#4)t(F#3F#4)t(E3F#3F#4)t(F#3F#4)t|]*(9)
4e, 3 16e, 4e
python Interpreter.py "Bpm(80)[|:2D#2q(F#3Bb3D#3)sp1s(F#3Bb3D#3)tBb2q(F#3Bb3D#3)qD#2q(F#3Bb3D#3)sp1s(F#3Bb3D#3)tBb2q(F#3Bb3D#3)qD#2q(F#3Bb3D#3)sp1s(F#3Bb3D#3)tBb2q(F#3Bb3D#3)qD#2q(F#3Bb3D#3)sp1s(F#3Bb3D#3)tB2q(G#3B3E3)q|]*(12)[|:9(F#3C3)tF#3t(E3F#3)tF#3t|]*(96)[Inst(2)|:3p7op1qG#4qBb4sG#4sBb4sp1sEb4qp2q|]*(12)" "fullsong"
Sol# G#
Sib Bb
Mib Eb
[G#q Bbs]
Bpm(80)[Inst(2)|:3p15qG#4qBb4sG#4sBb4sp1sEb4qp1q|]*(1)

View File

@@ -0,0 +1,21 @@
import twitter
import json
import requests
import _pickle as pickle
import sys
import schedule
import time
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
api=twitter.Api(consumer_key=consumer_key,
consumer_secret=consumer_secret,
access_token_key=access_token,
access_token_secret=access_token_secret)
for line in api.getstreamfilter():
print (line)

View File

@@ -0,0 +1,46 @@
import twitter
import json
import requests
import sys
import schedule
import time
since_id = None
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
location = ""
json_data = "{\"tweets\":["
def getTweets():
global json_data
print('getting tweets')
with open('/files/lastid', 'r') as file:
since_id = file.readline()
if (since_id == ""):
since_id = None
api=twitter.Api(consumer_key=consumer_key,
consumer_secret=consumer_secret,
access_token_key=access_token,
access_token_secret=access_token_secret)
temp = api.GetMentions(since_id=since_id, count=None,max_id=None,trim_user=False,contributor_details=False,include_entities=True)
if len(temp) > 0:
for item in temp:
data = {}
data['id'] = item.id
data['UserName'] = item.user.name
data['Date'] = item.created_at
data['text'] = item.text
data['location'] = ""
data['success'] = "no"
json_data = json_data + json.dumps(data) + ","
with open('/files/lastid', 'w') as outfile:
outfile.write(temp[0].id_str)
with open(location + 'tweets.json', "a") as outfile:
json_data = json_data[:len(json_data)-1] + "]}"
outfile.write(json_data)
print('wrote some json shit')
getTweets()

View File

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,4 @@
python-twitter==3.4.1
schedule==0.5.0
pymongo==2.8
miditoaudio==0.1.1