def follow(self, target): current_time = time() user_following_tl = Timeline(self.client, following_key(self.user)) user_following_tl.add(target, current_time) target_follower_tl = Timeline(self.client, follower_key(target)) target_follower_tl.add(self.user, current_time)
def singlebeat(beat, *args, **kwargs): beat_timeline = Timeline() time = 0.0 beat_timeline.add(time+0.0, beat) print "Rendering beat audio..." beat_data = beat_timeline.render() return beat_data
def singlenote(note_number, *args, **kwargs): singlenote_timeline = Timeline() time = 0.0 # Keep track of currect note placement time in seconds # Strum out root chord to finish chord = kwargs['progression'][0] singlenote_timeline.add(time + 0.0, Hit(chord.notes[note_number], 3.0)) print "Rendering singlenote audio..." singlenote_data = singlenote_timeline.render() return singlenote_data
def playchords(imu): key = Note('E3') scale = Scale(key, 'harmonic minor') progression = Chord.progression(scale, base_octave=key.octave) time = 0.0 timeline = Timeline() chord = progression[0] d = 3.0 #length of time (seconds) chords = [Hit(chord.notes[0], d), Hit(chord.notes[1], d), Hit(chord.notes[2], d), Hit(chord.notes[0], d)] amp = 0.25 #Amplitude thrd = None while True: timeline = Timeline() acc = imu.getacc() #print "acc is {}".format(acc) ax, ay, az = acc if ax > 1.5: timeline.add(0.0, chords[0]) elif ax < -1.5: timeline.add(0.0, chords[1]) if ay > 1.5: timeline.add(0.0, chords[2]) elif ay < -1.5: timeline.add(0.0, chords[3]) data = timeline.render() * amp if thrd == None or not thrd.isAlive(): thrd = threading.Thread(target=play, args=(data,)) thrd.start()
def arpeggio(*args, **kwargs): arpeggio_timeline = Timeline() time = 0.0 # Keep track of currect note placement time in seconds # Add progression to timeline by arpeggiating chords from the progression for index in [0, 1]: chord = kwargs['progression'][index] root, third, fifth = chord.notes arpeggio = [root, third, fifth, third, root, third, fifth, third] for i, interval in enumerate(arpeggio): ts = float(i * 2) / len(arpeggio) arpeggio_timeline.add(time + ts, Hit(interval, 1.0)) time += 2.0 print "Rendering arpeggio audio..." arpeggio_data = arpeggio_timeline.render() return arpeggio_data
def strum(*args, **kwargs): strum_timeline = Timeline() time = 0.0 # Keep track of currect note placement time in seconds # Strum out root chord to finish chord = kwargs['progression'][0] strum_timeline.add(time + 0.0, Hit(chord.notes[0], 4.0)) strum_timeline.add(time + 0.1, Hit(chord.notes[1], 4.0)) strum_timeline.add(time + 0.2, Hit(chord.notes[2], 4.0)) strum_timeline.add(time + 0.3, Hit(chord.notes[1].transpose(12), 4.0)) strum_timeline.add(time + 0.4, Hit(chord.notes[2].transpose(12), 4.0)) strum_timeline.add(time + 0.5, Hit(chord.notes[0].transpose(12), 4.0)) print "Rendering strum audio..." strum_data = strum_timeline.render() return strum_data
if note.index == "G3": note = random.choice(G3, A3, F3) if note.index == "A3": note = random.choice(A3, B3, G3) if note.index == "B3": note = random.choice(B3, C3, A3) if note.index == "C4": note = random.choice(B3, C4) print "Playing audio..." data = timeline.render() playback.play(data) print "Done!" timeline.add(time, Hit(note, 1)) # Resolve print "Rendering audio..." print "Playing audio..." playback.play(data) print "Done!"
noteAbove = "c%i" % (inputNote.octave + 1) return(random.choice([Note(noteBelow),Note(noteAbove)])) for w in range(0,22): if w == 0: melodyArray = [] bassArray = [] bassArray.append(Note("C2")) melodyArray.append(Note(scale.transpose(bassArray[0],9))) if (w % 2 == 0): timeline.add((w/2)*.5,Hit(bassArray[w/2],1)) bassNote = bassArray[w/2] #Define Melody Array bassArray.append(nextBassNote(bassArray[w/2-1])) melodyArray.append(nextNote(melodyArray[w-1],bassArray[w%2])) time = 0.0 #Populate Timeline for note in melodyArray:
progressions.append(make_progression_part()) voicings.append(make_voicing_part(len(progressions[-1]))) rhythms.append(make_rhythm_part()) melodies.append(make_melody_part(len(rhythms[-1]))) # Render the progressions and melodies in patterns song_length = randint(2, 3) * complexity // 2 for _ in range(song_length): i = randint(0, complexity - 1) render_progression(progressions[i], voicings[i]) j = randint(0, complexity - 1) render_melody(rhythms[j], melodies[j]) # Strum out root chord to finish chord = key_chords[0] timeline.add(time + 0.0, Hit(chord.notes[0], 4.0)) timeline.add(time + 0.1, Hit(chord.notes[1], 4.0)) timeline.add(time + 0.2, Hit(chord.notes[2], 4.0)) timeline.add(time + 0.3, Hit(chord.notes[1].transpose(12), 4.0)) timeline.add(time + 0.4, Hit(chord.notes[2].transpose(12), 4.0)) timeline.add(time + 0.5, Hit(chord.notes[0].transpose(12), 4.0)) print("Rendering audio...") data = timeline.render() # Reduce volume to 25% data = data * 0.25 #print("Playing audio...") print("Saving audio to " + filepath)
timeline = Timeline() note = key # Semi-randomly queue notes from the scale for i in xrange(64): if note.index > 50 or note.index < 24: # If note goes out of comfort zone, randomly place back at base octave note = scale.get(random.randrange(4) * 2) note = note.at_octave(key.octave) else: # Transpose the note by some small random interval note = scale.transpose(note, random.choice((-2, -1, 1, 2))) length = random.choice((0.125, 0.125, 0.25)) timeline.add(time, Hit(note, length + 0.125)) time += length # Resolve note = scale.transpose(key, random.choice((-1, 1, 4))) timeline.add(time, Hit(note, 0.75)) # Tension timeline.add(time + 0.5, Hit(key, 4.0)) # Resolution print "Rendering audio..." data = timeline.render() print "Applying chorus effect..." data = effect.chorus(data, freq=3.14159)
def main(argv): try: opts, args = getopt.getopt(argv, "hdsm", ['help', 'debug', 'startup', 'morning']) except getopt.GetoptError: usage() sys.exit(2) global _debug _debug = 0 morning = False for opt, arg in opts: if opt in ("-h", "--help"): usage() sys.exit() if opt in ("-m", "--morning"): morning = True _debug = 1 if opt == '-d': _debug = 1 if opt in ("-s", "--startup"): import time time.sleep(90) #os.system("/usr/bin/tvservice -o") # Increase chance of singing at sunrise/sunset import ephem birdcage = ephem.Observer() birdcage.lat = '51.497517' birdcage.lon = '0.080380' birdcage.date = str(datetime.datetime.now()) birdcage.elevation = 5 sun = ephem.Sun() next_sunrise = birdcage.next_rising(sun) early_next_sunrise = ephem.Date(next_sunrise - 15 * ephem.minute) late_next_sunrise = ephem.Date(next_sunrise + 15 * ephem.minute) next_sunset = birdcage.next_setting(sun) early_next_sunset = ephem.Date(next_sunset - 15 * ephem.minute) late_next_sunset = ephem.Date(next_sunset + 15 * ephem.minute) sunrise = False; sunset = False; if (birdcage.date > early_next_sunrise and birdcage.date < late_next_sunrise): #print 'Sunrise roll' sunrise = true; dice_roll = random.choice([1,2,3,4,5,6,7,8]) elif (birdcage.date > early_next_sunset and birdcage.date < late_next_sunset): #print 'Sunset roll' sunset = true; dice_roll = random.choice([1,2,3,4,5,6,7,8]) else: dice_roll = random.choice([1,2,3,4,5,6]) if (dice_roll < 5 and _debug <> 1): #print "Going back to sleep" sys.exit() # We're alive, import what else we need now sys.path.append(os.path.join(os.path.dirname(__file__), 'python-musical')) from musical.theory import Note, Scale, Chord from musical.audio import effect, playback from timeline import Hit, Timeline # Define key and scale key = Note((random.choice(Note.NOTES), random.choice([2,3,3]))) scales = ['major', 'minor', 'melodicminor', 'harmonicminor', 'pentatonicmajor', 'bluesmajor', 'pentatonicminor', 'bluesminor', 'augmented', 'diminished', 'wholehalf', 'halfwhole', 'augmentedfifth', 'japanese', 'oriental', 'ionian', 'phrygian', 'lydian', 'mixolydian', 'aeolian', 'locrian'] random.shuffle(scales) scale = Scale(key, random.choice(scales)) #print key #print scale # Grab progression chords from scale starting at the octave of our key progression = Chord.progression(scale, base_octave=key.octave) time = 0.0 # Keep track of correct note placement time in seconds timeline = Timeline() # Pick a notes from a chord randomly chosen from a list of notes in this progression chord = progression[ random.choice(range(len(progression)-1)) ] notes = chord.notes melodies = [ [0.8, 0.2], [0.4, 0.2], [0.2, 0.8], [0.2, 0.4], [0.6, 0.2], [0.4, 0.4, 0.2], [0.6, 0.1, 0.1], [0.8, 0.1, 0.2], [0.2, 0.2, 0.2], [0.2, 0.4, 0.2], [1.0, 0.1, 0.2, 0.1, 0.2, 0.10, 0.1], [0.8, 0.4, 0.1, 0.2, 0.4, 0.1, 0.2], [0.8, 0.4, 0.4, 0.2, 0.2, 0.1, 0.1], [0.4, 0.0, 0.1, 0.1, 0.2, 0, 0.1, 0.4], [0.1, 0.1, 0.1, 0.0, 0.2, 0.0, 0.1, 0.2, 0.4], [0.8, 0.4, 0.1, 0.4, 0.2, 0.2, 0.1, 0.2, 0.8, 0.1, 0.4, 0.1], [0.2, 0.2, 0.4, 0.2, 0.1, 0.1, 0.0, 0.2], [1.0, 0.1, 0.2, 0.1, 0.2, 0.2], [0.2, 0.1, 0.2, 0.4, 0.1, 0.2, 0.4], [0.4, 0.1, 0.4, 0.2, 0.4, 0.1, 0.4, 0.2], [0.1, 0.1, 0.1, 0.2, 0.1, 0.1, 0.2], [0.1, 0.1, 0.1, 0.2, 0.1, 0.1, 0.1, 0.2, 0.0], [0.1, 0.0, 0.1, 0.0, 0.1, 0.0, 0.2, 0.0, 0.2, 0.0, 0.1, 0.1, 0.3], ] if sunrise or sunset: random_melody = random.choice(melodies[0:12]) else: random_melody = random.choice(melodies) # Testing a new melody-generation idea - duncan 11/4/20 # - needs more work, disabling for now - 12/4/20 #random_melody = [] #melody_length = random.randrange(1, 12) # #for i in range(0, melody_length): # random_melody.append( round(random.uniform(0.1, 0.6), 1) ) # test end if morning: random_melody = melodies[-1] print random_melody last_interval = 0.0 last_transpose = 0 for i, interval in enumerate(random_melody): random_note = random.choice(notes) # the first note should be high # identical intervals should often hold the same pitch # otherwise, pick a random pitch if i == 0: random_transpose = random.choice([8, 12]) elif (last_interval == interval): if random.choice([0,1,2]) == 2: random_transpose = last_transpose else: random_transpose = 0 else: random_transpose = random.choice([0,2,4,6,8,10,12]) last_interval = interval last_transpose = random_transpose note = random_note.transpose(random_transpose) #print note # favour queued notes, but occasionally overlap them too if (random.choice([1,2,3,4,5,6]) > 2): time = time + interval timeline.add(time, Hit(note, interval)) else: timeline.add(time, Hit(note, interval)) time = time + interval #print "Rendering audio..." data = timeline.render() # Reduce volume to 50% data = data * 0.5 print "Playing audio..." if morning: for i in range(2): playback.play(data) else: for i in range(random.choice([1,2])): playback.play(data)
def make_sound(type): mytimeline = Timeline() mytimeline.add(0, Hit(type, 1, sound_string[type])) data = mytimeline.render() playback.play(data)
def get_timeline_from_hlr(hlr): timeline = Timeline() for t, chord, duration in hlr: for note in chord.notes: timeline.add(t, Hit(note, duration)) return timeline
class TestTimeline(unittest.TestCase): def setUp(self): self.client = Redis(decode_responses=True) self.client.flushdb() self.tl = Timeline(self.client, "blog::timeline") self.blogs = [ {"id": "blog::100", "time": 1000}, {"id": "blog::101", "time": 1500}, {"id": "blog::102", "time": 1550}, {"id": "blog::103", "time": 1700}, {"id": "blog::104", "time": 1750}, {"id": "blog::105", "time": 2500} ] self.reversed_blogs = list(reversed(self.blogs)) def test_add(self): self.assertEqual( self.tl.pagging(1, 10), [] ) self.tl.add("hello world", 10086) self.assertNotEqual( self.tl.pagging(1, 10), [] ) def test_remove(self): self.tl.add("hello world", 10086) self.tl.remove("hello world") self.assertEqual( self.tl.pagging(1, 10), [] ) def test_count(self): self.assertEqual( self.tl.count(), 0 ) self.tl.add("hello world", 10086) self.assertEqual( self.tl.count(), 1 ) def test_pagging_when_timeline_empty(self): self.assertEqual( self.tl.pagging(1, 10), [] ) def test_pagging_when_timeline_not_empty(self): for blog in self.blogs: self.tl.add(blog["id"], blog["time"]) result = self.tl.pagging(1, 10) for i in range(len(self.blogs)): self.assertEqual( result[i], self.reversed_blogs[i]["id"] ) result_with_time = self.tl.pagging(1, 10, True) for i in range(len(self.blogs)): self.assertEqual( result_with_time[i][0], self.reversed_blogs[i]["id"] ) self.assertEqual( result_with_time[i][1], self.reversed_blogs[i]["time"] ) def test_pagging_with_indexing(self): for blog in self.blogs: self.tl.add(blog["id"], blog["time"]) self.assertEqual( self.tl.pagging(1, 1)[0], self.reversed_blogs[0]["id"] ) self.assertEqual( self.tl.pagging(2, 1)[0], self.reversed_blogs[1]["id"] ) def test_fetch_by_time_range_when_timeline_empty(self): self.assertEqual( self.tl.fetch_by_time_range( self.blogs[0]["time"], self.blogs[5]["time"], 1, 10 ), [] ) def test_fetch_by_time_range_when_timeline_not_empty(self): for blog in self.blogs: self.tl.add(blog["id"], blog["time"]) result = self.tl.fetch_by_time_range( self.blogs[0]["time"], self.blogs[5]["time"], 1, 10 ) for i in range(len(self.reversed_blogs)): self.assertEqual( result[i], self.reversed_blogs[i]["id"] ) result_with_time = self.tl.fetch_by_time_range( self.blogs[0]["time"], self.blogs[5]["time"], 1, 10, True ) for i in range(len(self.reversed_blogs)): self.assertEqual( result_with_time[i][0], self.reversed_blogs[i]["id"] ) self.assertEqual( result_with_time[i][1], self.reversed_blogs[i]["time"] ) def test_fetch_by_time_range_with_indexing(self): for blog in self.blogs: self.tl.add(blog["id"], blog["time"]) self.assertEqual( self.tl.fetch_by_time_range( self.blogs[0]["time"], self.blogs[5]["time"], 1, 1 )[0], self.reversed_blogs[0]["id"] ) self.assertEqual( self.tl.fetch_by_time_range( self.blogs[0]["time"], self.blogs[5]["time"], 2, 1 )[0], self.reversed_blogs[1]["id"] )
textInput = input('please input some text: ') print('textInput:', textInput) # encode in a bytearray textBytes = textInput.encode() print('textBytes', textBytes) # hash the text textHash = hashlib.md5() textHash.update(textBytes) digest = textHash.digest() print('digest:', digest) # convert bytes to integers integers = [n for n in digest] print(integers) for char in digest: print(char) # play the notes time = 0.0 timeline = Timeline() for pitch in integers: print(pitch) timeline.add(time, Hit(Note(pitch % 32 + 24), 0.6)) time += 0.6 data = timeline.render() playback.play(data)
chords = [[], [Note("C3"),Note("E3"),Note("G3")], [Note("D3"),Note("F3"),Note("A3")], [Note("E3"),Note("G3"),Note("B3")], [Note("F3"),Note("A3"),Note("C4")], [Note("G3"),Note("B3"),Note("D4")], [Note("A3"),Note("C4"),Note("E4")], [Note("B3"),Note("D4"),Note("F4")], [Note("C4"),Note("E4"),Note("G4")], ] bassNote = bassProgression for x in range(0,8): timeline.add(x*.5,Hit(bassProgression[x],1)) time = 0.0 def getChord(inputNote): returnChord = [] print inputNote.note if inputNote.note == "c": returnChord = chords[1] elif inputNote.note == "d": returnChord = chords[2] elif inputNote.note == "e": returnChord = chords[3]
# Grab progression chords from scale starting at the octave of our key progression = Chord.progression(scale, base_octave=key.octave) time = 0.0 # Keep track of currect note placement time in seconds timeline = Timeline() # Add progression to timeline by arpeggiating chords from the progression for index in [0, 2, 3, 1, 0, 2, 3, 4, 5, 4, 0]: chord = progression[index] root, third, fifth = chord.notes arpeggio = [root, third, fifth, third, root, third, fifth, third] for i, interval in enumerate(arpeggio): ts = float(i * 2) / len(arpeggio) timeline.add(time + ts, Hit(interval, 1.0)) time += 2.0 # Strum out root chord to finish chord = progression[0] timeline.add(time + 0.0, Hit(chord.notes[0], 4.0)) timeline.add(time + 0.1, Hit(chord.notes[1], 4.0)) timeline.add(time + 0.2, Hit(chord.notes[2], 4.0)) timeline.add(time + 0.3, Hit(chord.notes[1].transpose(12), 4.0)) timeline.add(time + 0.4, Hit(chord.notes[2].transpose(12), 4.0)) timeline.add(time + 0.5, Hit(chord.notes[0].transpose(12), 4.0)) print "Rendering audio..." data = timeline.render()
def get (self, request): ############################## # check overlaps of intervals, uniqueness identified via the column : overlapchecks = [ (PersonZusage, 'person'), (Fachgebiet, 'kuerzel'), (Stelle, 'stellennummer'), (StellenwertigkeitIntervalle, 'wertigkeit'), (Zuordnung, 'stelle'), (Besetzung, 'stelle'), ] overlapmsg = [] for o in overlapchecks: # print o[0] for k in o[0].objects.values(o[1]).distinct().all(): qs = o[0].objects.filter (**{ o[1] + '__exact': k[o[1]]}) violationList= self.check_overlap (qs, o[1]) if violationList: violationURLs = [ (urlresolvers.reverse ('admin:stellenplan_' + o[0].__name__.lower() + '_change', args=(v[0],)), urlresolvers.reverse ('admin:stellenplan_' + o[0].__name__.lower() + '_change', args=(v[1],)), qs.get(id=v[0]).__unicode__(), qs.get(id=v[1]).__unicode__(), ) for v in violationList ] overlapmsg.append({'module_name': o[0].__name__, 'field': o[1].capitalize(), 'violationUrls': violationURLs}) #print overlapmsg ############################## # Konsistenz der Verknuepfungen: Teilmengen der intervalkle müssen eingehalten werden # Klasse: von -bis muss Teilintervall des foreign keys sein teilintervallbeziehungen = [(Zusage, "fachgebiet"), (Zuordnung, "fachgebiet"), (Zuordnung, "stelle"), # (Besetzung, "person"), (Besetzung, "stelle"), ] teilintervallkonflikte = filter (lambda x: x[2], [(tib[0].__name__, tib[1].capitalize(), [ ( urlresolvers.reverse ('admin:stellenplan_' + tib[0].__name__.lower() + '_change', args = (entry.pk,)), urlresolvers.reverse ('admin:stellenplan_' + getattr (entry, tib[1]).__class__.__name__.lower() + '_change', args = (getattr (entry, tib[1]).pk,)), entry.__unicode__(), getattr (entry, tib[1]).__unicode__() ) for entry in tib[0].objects.all() if not (( entry.von >= getattr (entry, tib[1]).von ) and ( entry.von <= getattr (entry, tib[1]).bis ) and ( entry.bis >= getattr (entry, tib[1]).von ) and ( entry.bis <= getattr (entry, tib[1]).bis ) ) ]) for tib in teilintervallbeziehungen ] ) ############################## # Wurden stellen mehrfach besetzt? use following backwords: # https://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects besetzungStelleKonflikt = [] zuordnungStelleKonflikt = [] for stelle in Stelle.objects.all(): ## print "----" ## print "Stelle: ", stelle tlBesetzung = Timeline() besetzungenDieserStelle = stelle.besetzung_set.all() for bes in besetzungenDieserStelle: tlBesetzung.add (bes.von, bes.bis, bes.prozent) tlZuordnung = Timeline() zuordnungenDieserStelle = stelle.zuordnung_set.all() for zu in zuordnungenDieserStelle: tlZuordnung.add (zu.von, zu.bis, zu.prozent) conflictsBesetzung = tlBesetzung.aboveThreshold(stelle.prozent) conflictsZuordnung = tlZuordnung.aboveThreshold(stelle.prozent) ## print "Conflicts Zuordnung" ## pp (conflictsZuordnung) ## tlZuordnung.dump() if conflictsBesetzung: tmp = [] for c in conflictsBesetzung: tmp.append ((c[0], c[1], c[2], [(b.__unicode__(), urlresolvers.reverse ('admin:stellenplan_besetzung_change', args = (b.pk,)) ) for b in besetzungenDieserStelle.exclude(bis__lt = c[0]).exclude(von__gt = c[1]).all() ])) besetzungStelleKonflikt.append((stelle, urlresolvers.reverse ('admin:stellenplan_stelle_change', args = (stelle.pk,)), tmp)) if conflictsZuordnung: tmp = [] for c in conflictsZuordnung: tmp.append ((c[0], c[1], c[2], [(b.__unicode__(), urlresolvers.reverse ('admin:stellenplan_zuordnung_change', args = (b.pk,)) ) for b in zuordnungenDieserStelle.exclude(bis__lt = c[0]).exclude(von__gt = c[1]).all() ])) zuordnungStelleKonflikt.append((stelle, urlresolvers.reverse ('admin:stellenplan_stelle_change', args = (stelle.pk,)), tmp)) ## print "----" ## pp(besetzungStelleKonflikt) ## pp(zuordnungStelleKonflikt) ############################## # welche Personen wurden noch nicht besetzt, sind also nicht finanziert? # gruppiere Personen nach Personalnummer, bilde jeweils eine Timeline, und ziehe davon die Besetzungstimeline ab, die für diese Personalnummer entsteht personUnbesetzt = [] for pGrouped in Person.objects.values('personalnummer').distinct().all(): # print pGrouped pTl = Timeline () bTl = Timeline () for p in PersonZusage.objects.all().filter(person__personalnummer__exact = pGrouped['personalnummer']): # print p pTl.add (p.von, p.bis, p.prozent) for b in Besetzung.objects.all().filter(person__personalnummer__exact = pGrouped['personalnummer']): # print b bTl.add (b.von, b.bis, b.prozent) pTl.addTL (bTl, -1) fehlendeBesetzung = pTl.aboveThreshold(0) if fehlendeBesetzung: # pp(fehlendeBesetzung) personUnbesetzt.append({ 'person': [ {'name': p.__unicode__(), 'url': urlresolvers.reverse ('admin:stellenplan_person_change', args = (p.pk,))} for p in Person.objects.all().filter(personalnummer__exact = pGrouped['personalnummer'])], 'intervalle': fehlendeBesetzung, 'besetzung': [ {'name': b.__unicode__(), 'url': urlresolvers.reverse ('admin:stellenplan_besetzung_change', args = (b.pk,))} for b in Besetzung.objects.all().filter(person__personalnummer__exact = pGrouped['personalnummer'])] }) # pp (personUnbesetzt) ############################## # Wurden Personen auf Stellen besetzt, die eine geringere Wertigkeit hat als die Person? # Was heisst "geringer", weniger Personalpunkte? # TODO: ist ist Frage der gleichzeitgikeit unterschiedllcher Besetzungen / Zusagen nicht klar wertigkeitNichtAusreichend = [] ## wertigkeitNichtAusreichend = [ {'besetzung': b.__unicode__(), ## 'person': {'text': b.person.__unicode__(), ## 'url': urlresolvers.reverse ('admin:stellenplan_person_change', ## args = (b.person.pk,)) }, ## 'stelle': {'text': b.stelle.__unicode__(), ## 'url': urlresolvers.reverse ('admin:stellenplan_stelle_change', ## args = (b.stelle.pk,)) }, ## 'url': urlresolvers.reverse ('admin:stellenplan_besetzung_change', ## args = (b.pk,)) ## } ## for b in Besetzung.objects.all() ## if (b.person.wertigkeit != ## b.stelle.wertigkeit )] # pp(wertigkeitNichtAusreichend) ############################## return render (request, 'stellenplan/konsistenz.html', {'overlap': overlapmsg, 'teilintervallkonflikte': teilintervallkonflikte, 'besetzungStelleKonflikt': besetzungStelleKonflikt, 'zuordnungStelleKonflikt': zuordnungStelleKonflikt, 'personUnbesetzt': personUnbesetzt, 'wertigkeitNichtPassend': wertigkeitNichtAusreichend, })
timeline = Timeline() note = key # Semi-randomly queue notes from the scale for i in range(64): if note.index > 50 or note.index < 24: # If note goes out of comfort zone, randomly place back at base octave note = scale.get(random.randrange(4) * 2) note = note.at_octave(key.octave) else: # Transpose the note by some small random interval note = scale.transpose(note, random.choice((-2, -1, 1, 2))) length = random.choice((0.125, 0.125, 0.25)) timeline.add(time, Hit(note, length + 0.125)) time += length # Resolve note = scale.transpose(key, random.choice((-1, 1, 4))) timeline.add(time, Hit(note, 0.75)) # Tension timeline.add(time + 0.5, Hit(key, 4.0)) # Resolution print("Rendering audio...") data = timeline.render() print("Applying chorus effect...") data = effect.chorus(data, freq=3.14159)
def main(argv): try: opts, args = getopt.getopt(argv, "hds", ['help', 'debug', 'startup']) except getopt.GetoptError: usage() sys.exit(2) global _debug _debug = 0 for opt, arg in opts: if opt in ("-h", "--help"): usage() sys.exit() elif opt == '-d': _debug = 1 elif opt in ("-s", "--startup"): import time time.sleep(90) os.system("/usr/bin/tvservice -o") _debug = 1 # Increase chance of singing at sunrise/sunset import ephem birdcage = ephem.Observer() birdcage.lat = '51.5034070' birdcage.lon = '-0.1275920' birdcage.elevation = 19 sun = ephem.Sun() next_sunrise = birdcage.next_rising(sun) early_next_sunrise = ephem.Date(next_sunrise - 15 * ephem.minute) late_next_sunrise = ephem.Date(next_sunrise + 15 * ephem.minute) next_sunset = birdcage.next_setting(sun) early_next_sunset = ephem.Date(next_sunset - 15 * ephem.minute) late_next_sunset = ephem.Date(next_sunset + 15 * ephem.minute) if (birdcage.date > early_next_sunrise and birdcage.date < late_next_sunrise): print 'Sunrise roll' dice_roll = random.choice([1,2,3,4,5]) elif (birdcage.date > early_next_sunset and birdcage.date < late_next_sunset): print 'Sunset roll' dice_roll = random.choice([1,2,3,4,5]) else: dice_roll = random.choice([1,2,3,4,5,6]) if (dice_roll < 5 and _debug <> 1): print "Going back to sleep" sys.exit() # We're alive, import what else we need now sys.path.append(os.path.join(os.path.dirname(__file__), 'python-musical')) from musical.theory import Note, Scale, Chord from musical.audio import effect, playback from timeline import Hit, Timeline # Define key and scale key = Note((random.choice(Note.NOTES), random.choice([2,3,3]))) scales = ['major', 'minor', 'melodicminor', 'harmonicminor', 'pentatonicmajor', 'bluesmajor', 'pentatonicminor', 'bluesminor', 'augmented', 'diminished', 'wholehalf', 'halfwhole', 'augmentedfifth', 'japanese', 'oriental', 'ionian', 'phrygian', 'lydian', 'mixolydian', 'aeolian', 'locrian'] scale = Scale(key, random.choice(scales)) print key print scale # Grab progression chords from scale starting at the octave of our key progression = Chord.progression(scale, base_octave=key.octave) time = 0.0 # Keep track of currect note placement time in seconds timeline = Timeline() # Pick a notes from a chord randomly chosen from a list of notes in this progression chord = progression[ random.choice(range(len(progression)-1)) ] notes = chord.notes melodies = [ [1.0, 0.1, 0.2, 0.1, 0.2, 0.10, 0.1], [0.8, 0.1, 0.1, 0.2], [0.8, 0.4, 0.1, 0.2, 0.4, 0.1, 0.2], [0.8, 0.4, 0.4, 0.2, 0.2, 0.1, 0.1], [0.4, 0.0, 0.1, 0.1, 0.2, 0, 0.1, 0.4], [0.1, 0.1, 0.1, 0.0, 0.2, 0.0, 0.1, 0.2, 0.4], [0.8, 0.4, 0.1, 0.4, 0.2, 0.2, 0.1, 0.2, 0.8, 0.1, 0.4, 0.1], [0.2, 0.2, 0.4, 0.2, 0.1, 0.1, 0.0, 0.2], [1.0, 0.1, 0.2, 0.1, 0.2, 0.2], [0.2, 0.1, 0.2, 0.4, 0.1, 0.2, 0.4], [0.4, 0.1, 0.4, 0.2, 0.4, 0.1, 0.4, 0.2], [0.1, 0.1, 0.1, 0.2, 0.1, 0.1, 0.2], [0.1, 0.1, 0.1, 0.2, 0.1, 0.1, 0.1, 0.2, 0.0], [0.1, 0.0, 0.1, 0.0, 0.1, 0.0, 0.2, 0.0, 0.2, 0.0, 0.1, 0.1, 0.3], ] random_melody = random.choice(melodies) print random_melody last_interval = 0.0 last_transpose = 0 for i, interval in enumerate(random_melody): random_note = random.choice(notes) # the first note should be high # identical intervals should often hold the same pitch # otherwise, pick a random pitch if i == 0: random_transpose = random.choice([8, 12]) elif (last_interval == interval): if random.choice([0,1,2]) == 2: random_transpose = last_transpose else: random_transpose = 0 else: random_transpose = random.choice([0, 2,4,6,8,10,12]) last_interval = interval last_transpose = random_transpose note = random_note.transpose(random_transpose) #print note # favour queued notes, but occasionally overlap them too if (random.choice([1,2,3,4,5,6]) > 2): time = time + interval timeline.add(time, Hit(note, interval)) else: timeline.add(time, Hit(note, interval)) time = time + interval print "Rendering audio..." data = timeline.render() # Reduce volume to 95% data = data * 0.95 print "Playing audio..." for i in range(random.choice([1,2])): playback.play(data) print "Done!"