Skip to content

Commit

Permalink
fix Radiant Ensemble files
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesa08 committed Aug 24, 2022
1 parent 369bdd8 commit 60e7377
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 37 deletions.
63 changes: 37 additions & 26 deletions custom_animation_files/Laser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def __init__(self, midiTrack: MIDITrack, collection: bpy.types.Collection, **kwa
self.rotation_high = kwargs["rotation_high"]
self.note_low = kwargs["note_low"]
self.note_high = kwargs["note_high"]
self.obj = self.collection.all_objects["Circle"]
self.laser = self.collection.all_objects["Cylinder"]
self.objBase = kwargs["base"]
self.objEmitter = kwargs["emitter"]
self.preAnimate()

def preAnimate(self):
Expand All @@ -33,15 +33,15 @@ def preAnimate(self):

def animate(self):
# beginning
self.obj.rotation_euler.y = 0
self.obj.keyframe_insert(data_path="rotation_euler", index=1, frame=0)
self.objBase.rotation_euler.x = 0
self.objBase.keyframe_insert(data_path="rotation_euler", index=0, frame=0)
nextNote = self.midiTrack.notes[1] if 1 < len(self.midiTrack.notes) else None
if nextNote is not None:
# set a key on the next note (- 1)
self.obj.keyframe_insert(data_path="rotation_euler", index=1, frame=secToFrames(nextNote.timeOn - 1))
self.objBase.keyframe_insert(data_path="rotation_euler", index=0, frame=secToFrames(nextNote.timeOn - 1))

# turn laser off
showHideObj(self.laser, hide=True, frame=0)
showHideObj(self.objEmitter, hide=True, frame=0)



Expand All @@ -55,8 +55,8 @@ def animate(self):
curNote.timeOff = nextNote.timeOn

# set a timeOn key
self.obj.rotation_euler.y = radians(mapRangeLinear(curNote.noteNumber, self.note_low, self.note_high, self.rotation_low, self.rotation_high))
self.obj.keyframe_insert(data_path="rotation_euler", index=1, frame=secToFrames(curNote.timeOn))
self.objBase.rotation_euler.x = radians(mapRangeLinear(curNote.noteNumber, self.note_low, self.note_high, self.rotation_low, self.rotation_high))
self.objBase.keyframe_insert(data_path="rotation_euler", index=0, frame=secToFrames(curNote.timeOn))


if animDuration > 1:
Expand All @@ -66,43 +66,54 @@ def animate(self):

if animDuration < 4:
# not a break
self.obj.rotation_euler.y = radians(mapRangeLinear(curNote.noteNumber, self.note_low, self.note_high, self.rotation_low, self.rotation_high))
self.obj.keyframe_insert(data_path="rotation_euler", index=1, frame=secToFrames(nextNote.timeOn - timeDiff))
self.objBase.rotation_euler.x = radians(mapRangeLinear(curNote.noteNumber, self.note_low, self.note_high, self.rotation_low, self.rotation_high))
self.objBase.keyframe_insert(data_path="rotation_euler", index=0, frame=secToFrames(nextNote.timeOn - timeDiff))

if timeDiff == 1:
self.obj.keyframe_insert(data_path="rotation_euler", index=1, frame=secToFrames(curNote.timeOff))
self.objBase.keyframe_insert(data_path="rotation_euler", index=0, frame=secToFrames(curNote.timeOff))
else:
# return to 0
# insert a note off key before its done
self.obj.keyframe_insert(data_path="rotation_euler", index=1, frame=secToFrames(curNote.timeOff))
self.objBase.keyframe_insert(data_path="rotation_euler", index=0, frame=secToFrames(curNote.timeOff))

# set key after its done (+ 1)
self.obj.rotation_euler.y = 0
self.obj.keyframe_insert(data_path="rotation_euler", index=1, frame=secToFrames(curNote.timeOff + 1))
self.objBase.rotation_euler.x = 0
self.objBase.keyframe_insert(data_path="rotation_euler", index=0, frame=secToFrames(curNote.timeOff + 1))

# set a key on the next note (- 1)
self.obj.keyframe_insert(data_path="rotation_euler", index=1, frame=secToFrames(nextNote.timeOn - 1))
self.objBase.keyframe_insert(data_path="rotation_euler", index=0, frame=secToFrames(nextNote.timeOn - 1))


showHideObj(self.laser, hide=False, frame=secToFrames(curNote.timeOn))
showHideObj(self.laser, hide=True, frame=secToFrames(curNote.timeOff))
showHideObj(self.objEmitter, hide=False, frame=secToFrames(curNote.timeOn))
showHideObj(self.objEmitter, hide=True, frame=secToFrames(curNote.timeOff))



file = MIDIFile("/Users/james/github/MIDIFiles/testMidi/future_retro_laser.mid")
# file = MIDIFile("/Users/james/github/MIDIFiles/testMidi/AnimDraft3.mid")
# file = MIDIFile("/Users/james/github/MIDIFiles/testMidi/future_retro_laser.mid")
file = MIDIFile("/Users/james/github/MIDIFiles/testMidi/AnimDraft3.mid")

tracks = file.getMIDITracks()
laserTrack = tracks[0]
# laserTrack = file.findTrack("Laser")
# laserTrack = tracks[0]
laserTrack = file.findTrack("Laser")

settings = {
"rotation_low": -35,
"rotation_high": 52,
settingsLaser1 = {
"rotation_low": -27.3312,
"rotation_high": 62.8,
"note_low": min([note.noteNumber for note in laserTrack.notes]),
"note_high": max([note.noteNumber for note in laserTrack.notes])
"note_high": max([note.noteNumber for note in laserTrack.notes]),
"base": bpy.data.objects["LaserBase"],
"emitter": bpy.data.objects["Laser"]
}
settingsLaser2 = {
"rotation_low": -27.3312,
"rotation_high": 62.8,
"note_low": min([note.noteNumber for note in laserTrack.notes]),
"note_high": max([note.noteNumber for note in laserTrack.notes]),
"base": bpy.data.objects["LaserBase.001"],
"emitter": bpy.data.objects["Laser.001"]
}

animator = MIDIAnimatorNode()
animator.addInstrument(midiTrack=laserTrack, objectCollection=bpy.data.collections['Laser'], custom=Laser, customVars=settings)
animator.addInstrument(instrumentType="custom", midiTrack=laserTrack, objectCollection=bpy.data.collections['Laser'], custom=Laser, customVars=settingsLaser1)
animator.addInstrument(instrumentType="custom", midiTrack=laserTrack, objectCollection=bpy.data.collections['Laser'], custom=Laser, customVars=settingsLaser2)
animator.animate()
6 changes: 3 additions & 3 deletions custom_animation_files/drumstick_RaidentEnsemble.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from __future__ import annotations
from pprint import pprint
from MIDIAnimator.utils import mapRangeLinear, convertNoteNumbers
from MIDIAnimator.src.animation import MIDIAnimatorNode
from MIDIAnimator.src.instruments import Instrument
from MIDIAnimator.data_structures.midi import *
from MIDIAnimator.utils.blender import *
from MIDIAnimator.utils import mapRangeLinear
from mathutils import Vector, Euler
from dataclasses import dataclass
from typing import Dict, List
Expand Down Expand Up @@ -76,7 +76,7 @@ def __post_init__(self):

# build up noteToTarget table (one target per object for now)
for obj in self.targetCollection.all_objects:
note_number = int(obj.note_number)
note_number = convertNoteNumbers(obj.midi.note_number)[0]
self.noteToTargetTable[note_number] = obj


Expand Down Expand Up @@ -773,5 +773,5 @@ def animate(self):


animator = MIDIAnimatorNode()
animator.addInstrument(midiTrack=drums, objectCollection=drumsticks, custom=DrumstickInstrumentNew, customVars=settings) # Drumsticks
animator.addInstrument(instrumentType="custom", midiTrack=drums, objectCollection=drumsticks, custom=DrumstickInstrumentNew, customVars=settings) # Drumsticks
animator.animate()
2 changes: 1 addition & 1 deletion custom_animation_files/four-way-perc.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def filterFourWayNotes(self, track: MIDITrack):
return fourWayNotes

def getRotObj(self) -> None:
assert len(self.collection.all_objects) == 1, "please make sure you have 1 objects in the collection"
assert len(self.collection.all_objects) == 1, "please make sure you have 1 object in the collection"

for obj in self.collection.all_objects:
self.rotObj = obj
Expand Down
15 changes: 8 additions & 7 deletions custom_animation_files/hi-hats.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class KeyframeValue:
class HiHatInstrument(Instrument):
hiHatNotes: List[MIDINote]
def __init__(self, midiTrack: MIDITrack, collection: bpy.types.Collection, **kwargs):
super().__init__(midiTrack, collection, override=False)
self.override = False # we want to define how we want to animate it & dont use the API
super().__init__(midiTrack, collection, override=True)
self.override = True # we want to define how we want to animate it & dont use the API

self.hiHatTopObj = None
self.hiHatBottomObj = None
Expand Down Expand Up @@ -117,7 +117,7 @@ def __init__(self, midiTrack: MIDITrack, collection: bpy.types.Collection, **kwa
)
}

self.animate_loc()
# self.animate_loc()


def evalHiHatMotion(self, curNote: MIDINote, nextNote: MIDINote, index: int) -> None:
Expand Down Expand Up @@ -204,7 +204,7 @@ def getHiHatObjs(self) -> None:
def writeKey(self, time: float, value: float, noteNumber: int, handleType: str="ALIGNED", hit=False):
self.keyframes.append((time, value, noteNumber, handleType, hit))

def animate_loc(self):
def animate(self):
# writing to the keyframeDict here
for i, curNote in enumerate(self.hiHatNotes):
nextNote = self.hiHatNotes[i + 1] if i+1 < len(self.hiHatNotes) else None
Expand All @@ -217,7 +217,7 @@ def animate_loc(self):
for time, value, noteNumber, handleType, hit in keyframes:
obj = self.hiHatTopObj
if not hit:
obj.location[2] = (value * 0.8) + self.topOrigLoc.z # add it to itself?
obj.location[2] = (value * 0.1) + self.topOrigLoc.z # add it to itself?
obj.keyframe_insert(data_path="location", index=2, frame=secToFrames(time))

if hit:
Expand All @@ -233,13 +233,14 @@ def animate_loc(self):
# file = MIDIFile("/Users/james/github/MIDIFiles/testMidi/Drums_new.mid")
# drumTrack = file.findTrack("MIDI Region")

file = MIDIFile("/Users/james/github/MIDIFiles/testMidi/pipedream3_8_18_21_1.mid")
# file = MIDIFile("/Users/james/github/MIDIFiles/testMidi/pipedream3_8_18_21_1.mid")
file = MIDIFile("/Users/james/github/MIDIFiles/testMidi/AnimDraft3.mid")
drumTrack = file.findTrack("Drums")

# hiHats = bpy.data.collections['Hi-Hats']
hiHats = bpy.data.collections['DrumsHH']

animator = MIDIAnimatorNode()
animator.addInstrument(midiTrack=drumTrack, objectCollection=hiHats, custom=HiHatInstrument)
animator.addInstrument(instrumentType="custom", midiTrack=drumTrack, objectCollection=hiHats, custom=HiHatInstrument)
# animator.addInstrument(midiTrack=testTrack, objectCollection=bpy.data.collections['cubes'])
animator.animate()

0 comments on commit 60e7377

Please sign in to comment.