def remapTrack(self, tobj, tau=None, vLow=-2, vHigh=2, inst=127, fch=None, res=None, repeats=None): if res == None: res = self.resolution if res == None: print "Cannot remap track without resolution" return mObj = MidiObj(resolution=res) T = tobj.getMaxTime() print "T:", T if tau == None: tau = T tau = T rmap = RissetMapper(T, tau) reMax = rmap.get_te(T,0)[0] print "rmap(T):", reMax ch = 0 for v in range(vLow, vHigh+1): print "v: ", v #rtObj = self.remapv(tobj, v, tau, ch=ch, inst=10+v) if fch != None: ch = fch rtObj = self.remapv(tobj, v, tau, ch=ch, inst=inst) rtObj.trackName = "risset v=%s" % v if repeats: rt0 = TrackObj() for i in range(repeats): rt0.append(rtObj) rtObj = rt0 mObj.addTrack(rtObj) ch += 1 #mObj.resolution = rtObj.resolution mObj.loop = True return mObj
def gen(self, path, nnotes=200, motif=None): self.t = 0 if motif: motif = parse(motif) print "="*60 print "Generating Shepard Tones" tobj = TrackObj(trackName="Track1") for i in range(nnotes): dur = 1 if motif: j,dur = motif[i % len(motif)] if j == 'r': self.t += dur*self.ticksPerBeat continue else: j = i % 12 #print i, j notes = self.getChord(j, dur) self.t += dur*self.ticksPerBeat for note in notes: tobj.addNote(note) midiObj = MidiObj() midiObj.addTrack(tobj) midiObj.saveAsJSON(path) mpath = path.replace(".json", ".mid") midiObj.saveAsMidi(mpath)
def genTrackBasicBeat1(resolution): t = TrackObj() numMeasures = 8 tpb = resolution # ticks per beat bpmeasure = 4 # beats per measure for m in range(numMeasures): b = m * bpmeasure t0 = b * tpb print "b: %3d t: %8.3f" % (b, t0) # c p t v dur t.addNote(Note(0, 50, t0, 90, 0.25 * tpb)) t.addNote(Note(0, 50, t0 + 1 * tpb, 70, 0.25 * tpb)) t.addNote(Note(0, 50, t0 + 2 * tpb, 70, 0.25 * tpb)) t.addNote(Note(0, 50, t0 + 3 * tpb, 70, 0.25 * tpb)) t.setMaxTime(t0 + bpmeasure * tpb) m = MidiObj(resolution=tpb) m.addTrack(t) return m
def genTrackBasicBeat1(resolution): t = TrackObj() numMeasures = 8 tpb = resolution # ticks per beat bpmeasure = 4 # beats per measure for m in range(numMeasures): b = m*bpmeasure t0 = b * tpb print "b: %3d t: %8.3f" % (b, t0) # c p t v dur t.addNote(Note(0, 50, t0, 90, 0.25*tpb)) t.addNote(Note(0, 50, t0+1*tpb, 70, 0.25*tpb)) t.addNote(Note(0, 50, t0+2*tpb, 70, 0.25*tpb)) t.addNote(Note(0, 50, t0+3*tpb, 70, 0.25*tpb)) t.setMaxTime(t0 + bpmeasure*tpb) m = MidiObj(resolution=tpb) m.addTrack(t) return m
def remapTrack(self, tobj, tau=None, vLow=-2, vHigh=2, inst=127, fch=None, res=None, repeats=None): if res == None: res = self.resolution if res == None: print "Cannot remap track without resolution" return mObj = MidiObj(resolution=res) T = tobj.getMaxTime() print "T:", T if tau == None: tau = T tau = T rmap = RissetMapper(T, tau) reMax = rmap.get_te(T, 0)[0] print "rmap(T):", reMax ch = 0 for v in range(vLow, vHigh + 1): print "v: ", v #rtObj = self.remapv(tobj, v, tau, ch=ch, inst=10+v) if fch != None: ch = fch rtObj = self.remapv(tobj, v, tau, ch=ch, inst=inst) rtObj.trackName = "risset v=%s" % v if repeats: rt0 = TrackObj() for i in range(repeats): rt0.append(rtObj) rtObj = rt0 mObj.addTrack(rtObj) ch += 1 #mObj.resolution = rtObj.resolution mObj.loop = True return mObj
def gen(self, path, nnotes=200, motif=None): self.t = 0 if motif: motif = parse(motif) print "="*60 print "Generating Shepard Tones" tobj = TrackObj(trackName="Track1") for i in range(nnotes): dur = 1 if motif: j,dur = motif[i % len(motif)] else: j = i % 12 #print i, j notes = self.getChord(j, dur) for note in notes: tobj.addNote(note) midiObj = MidiObj() midiObj.addTrack(tobj) midiObj.saveAsJSON(path)
def genShepard(path, nvoices=5, noctaves=5, nnotes=200, motif=None): if motif: motif = parse(motif) print "="*60 print "Generating Shepard Tones" tobj = TrackObj(trackName="Track1") t = 0 for v in range(nvoices): sv = ShepVoice(noctaves, 12*v) for i in range(nnotes): j = i dur = 1 if motif: j,dur = motif[i % len(motif)] #print j, dur tOn, note = sv.getNote(t, j, dur) t += sv.ticksPerBeat*dur if note: #print i, note.toList() tobj.addNote(note) midiObj = MidiObj() midiObj.addTrack(tobj) midiObj.saveAsJSON(path)
def gen(self, path, nnotes=200, motif=None): self.t = 0 if motif: motif = parse(motif) print "=" * 60 print "Generating Shepard Tones" tobj = TrackObj(trackName="Track1") for i in range(nnotes): dur = 1 if motif: j, dur = motif[i % len(motif)] else: j = i % 12 #print i, j notes = self.getChord(j, dur) for note in notes: tobj.addNote(note) midiObj = MidiObj() midiObj.addTrack(tobj) midiObj.saveAsJSON(path)
def genShepard(path, nvoices=5, noctaves=5, nnotes=200, motif=None): if motif: motif = parse(motif) print "=" * 60 print "Generating Shepard Tones" tobj = TrackObj(trackName="Track1") t = 0 for v in range(nvoices): sv = ShepVoice(noctaves, 12 * v) for i in range(nnotes): j = i dur = 1 if motif: j, dur = motif[i % len(motif)] #print j, dur tOn, note = sv.getNote(t, j, dur) t += sv.ticksPerBeat * dur if note: #print i, note.toList() tobj.addNote(note) midiObj = MidiObj() midiObj.addTrack(tobj) midiObj.saveAsJSON(path)
def save(tObj, path): mObj = MidiObj() mObj.addTrack(tObj) mObj.saveAsJSON(path)
from PVMidi import TrackObj, MidiObj, Note def save(tObj, path): mObj = MidiObj() mObj.addTrack(tObj) mObj.saveAsJSON(path) path = "BluesRhythm1.mid" m = MidiObj(path) print m.tracks t = m.tracks[1] rt = t.rescaleByTime(t.rescaleTime(0.25, 2.0)) rt.scalePowerBySin() save(rt, "ris1.json")