[Closed] script converting from blender to max
Function maintains the callback for Blender file chooser
"""
self.clearMidiSettings()
try:
Common.filename = "None"
self.midi = MidiFile(_filename)
Common.filename = _filename
self.notesCopy = self.midi.noteList[:]
self.updateFilterCombos()
self.orderCons = len(self.midi.noteList)-1
self.rangeCons = self.midi.totalTime
self.fRangeVal = [0,self.rangeCons]
self.strDisp.note = (int)((self.midi.noteList[0].val%128)/12)*12
self.strDisp.time = (int)(self.midi.noteList[0].startT/1000)
self.isLoaded = True
except MidiFormatError, ex:
Draw.PupMenu("Error |"+str(ex))
except IOError:
Draw.PupMenu("Error |File incorrect or does not exist")
Draw.Redraw()
def noteFilter(self):
"""Wrap MidiFile.selectNotes function.
Prepares values retrieved from the interface to be used as the
filtering parameters.
Return list of notes fitting the selection parameters.
"""
noteVal = -1
channel = -1
instrument = -1
order = [0,1]
timeRange = [-1,-1]
if self.channEnabled:
channel = self.fChannVal
if self.instrEnabled:
instrument = self.fInstrVal
if self.notesEnabled:
noteVal = self.fNoteVal
if self.orderEnabled:
order = self.fOrdVal
if self.rangeEnabled:
timeRange = self.fRangeVal
return MidiFile.selectNotes(self.notesCopy,channel,instrument,noteVal\
,timeRange,order)
def dataExist(self,name,type):
"""Check whether object/datablock exists.
Arguments:
name -- a name of the object/datablock
type -- type of the object
"""
if not name:
return True
if (self.obNamesEnabled)\
and (not (type in (Common.MA,Common.TE,Common.WO))):
try:
if (Object.Get(name).type != Common.typeNames[type])\
and (type != Common.OB):
Draw.PupMenu("Error |" + "Object \""+name\
+ "\" does not contain " + Common.typeNames[type]\
+ " datablock")
return False
return True
except (ValueError, NameError):
Draw.PupMenu("Error |" + "Object \""+name\
+ "\" does not exist")
else:
try:
Common.getDatablock(name,type)
return True
except (ValueError, NameError):
Draw.PupMenu("Error |" + Common.typeNames[type]+" \""\
+name + "\" does not exist")
return False
def correctionMenu(self):
"""Display input for correction interval, perform correction on
given Ipo/action.
"""
ipoName = Blender.Draw.Create("")
i = Blender.Draw.Create(self.corrInterval)
tog = Blender.Draw.Create(1)
block = []
block.append(("IPO/Action", tog, "Enable for IPO, Disable for Actions"))
block.append(("IP/AC:", ipoName, 0, 255, "IPO/Action name"))
block.append(("Max interval: ", i, 1, 1000))
retval = Blender.Draw.PupBlock("IPO/Action Correction", block)
print "PupBlock returned", retval
print "text ", ipoName
print tog.val
self.corrInterval = int(i.val)
if not tog.val:
if ipoName.val in Armature.NLA.GetActions().keys():
Common.correctIpo(\
Armature.NLA.GetActions()[ipoName.val],\
self.corrInterval)
else:
Draw.PupMenu("Error |Action \""\
+ipoName.val + "\" does not exist")
else:
try:
Common.correctIpo(Ipo.Get(ipoName.val),\
self.corrInterval)
except (NameError,ValueError):
Draw.PupMenu("Error |IPO \""\
+ipoName.val + "\" does not exist")
def buttonEvents(self,event):
"""Handle events of identifier event launched by interface controls.
"""
## Exit the script.
if event == self.E_EXIT:
Draw.Exit()
## Invoke file loading.
elif event == self.E_LOAD:
Blender.Window.FileSelector(self.resetLoad, "Open MIDI file")
## Changes made in animation entries. Update repsective variables.
elif event == self.E_ANIM_UPDATE:
for i in range(0,self.entrCount):
## New Ipo/datablock type value.
if self.ipoTypeVals[i] != self.ipoTypeCombos[i].val:
self.ipoTypeVals[i] = self.ipoTypeCombos[i].val
self.ipoNames[i] = ""
self.objNames[i] = ""
self.pIpoNames[i] = ""
self.leadKeyConstr[i] = 0
else:
## New object/datablock name.
self.objNames[i] = self.objTBoxes[i].val
if not self.dataExist(
self.objNames[i],self.ipoTypeVals[i]):
self.objNames[i] = ""
self.ipoNames[i] = self.ipoTBoxes[i].val
## New Ipo/action name.
if self.ipoNames[i]:
if self.ipoTypeVals[i] != Common.AR:
try:
ipo = Ipo.Get(self.ipoNames[i])
if ipo.getBlocktype() == self.ipoTypeVals[i]:
self.leadKeyConstr[i] =\
len(Common.findKeys(ipo))
if not self.leadKeyConstr[i]:
Draw.PupMenu("Error |Ipo "\
+ self.ipoNames[i]\
+ " does not contain any keys.")
self.ipoNames[i] = ""
else:
Draw.PupMenu("Error |"\
+ Common.typeNames[ipo.getBlocktype()]\
+ " Ipo \"" + self.ipoNames[i]\
+ "\" not suitable for "\
+ Common.typeNames[self.ipoTypeVals[i]]\
+ " type")
self.ipoNames[i] = ""
self.leadKeyConstr[i] = 0
except (ValueError, NameError):
Draw.PupMenu("Error |Ipo \"" + \
self.ipoNames[i] + "\" does not exist")
self.ipoNames[i] = ""
self.leadKeyConstr[i] = 0
else:
if not self.ipoNames[i]\
in Armature.NLA.GetActions().keys():
Draw.PupMenu("Error |Action \"" + \
self.ipoNames[i] + "\" does not exist")
self.ipoNames[i] = ""
self.leadKeyConstr[i] = 0
else:
self.leadKeyConstr[i] =\
len(Armature.NLA.GetActions()[\
self.ipoNames[i]].getFrameNumbers())
if not self.leadKeyConstr[i]:
Draw.PupMenu("Error |Action "\
+ self.ipoNames[i]\
+ " does not contain any keys.")
self.ipoNames[i] = ""
else:
self.leadKeyConstr[i] = 0
## New pause Ipo/action name.
self.pIpoNames[i] = self.pIpoTBoxes[i].val
if self.pIpoNames[i]:
if self.ipoTypeVals[i] != Common.AR:
try:
ipo = Ipo.Get(self.pIpoNames[i])
if not (ipo.getBlocktype() ==\
self.ipoTypeVals[i]):
Draw.PupMenu("Error |"\
+ Common.typeNames[ipo.getBlocktype()]\
+" Ipo \"" + self.pIpoNames[i]\
+ "\" not suitable for "\
+ Common.typeNames[self.ipoTypeVals[i]]\
+ " type")
self.pIpoNames[i] = ""
except (ValueError, NameError):
Draw.PupMenu("Error |Ipo \"" + \
self.pIpoNames[i] + "\" does not exist")
self.pIpoNames[i] = ""
else:
if not self.pIpoNames[i]\
in Armature.NLA.GetActions().keys():
Draw.PupMenu("Error |Action \"" + \
self.pIpoNames[i] + "\" does not exist")
self.pIpoNames[i] = ""
## New leading key frame value.
self.leadKeys[i] = self.lKeySpins[i].val
if not self.leadKeys[i]:
self.leadKeys[i] = 1
## Scale toggle update.
self.scaleEnabled[i] = self.scaleToggles[i].val
## Hold toggle update.
self.holdEnabled[i] = self.holdToggles[i].val
## Reference velocity update.
self.velVals[i] = self.velSpins[i].val
## Relative vertical scalling toggle update.
self.relativeEnabled[i] = self.velToggles[i].val
## Pause Ipo/action scalling toggle update.
self.pScaleEnabled[i] = self.pScaleToggles[i].val
## Invoke reset of the animation entries.
elif event == self.E_CLEAR_ANIM:
self.clearAnimSettings()
## New value of the initial offset.
elif event == self.E_INOFF:
self.initOffset = self.inOffSpin.val
self.strDisp.framesOffset = self.initOffset
## Object/datablock name usage toggle update.
elif event == self.E_USE_OB:
self.obNamesEnabled = not self.obNamesEnabled
## Datablocks names have to be replaced with respective object
## names...
if self.obNamesEnabled:
for i in range(0,self.entrCount):
if (not (self.ipoTypeVals[i]\
in (Common.WO,Common.OB,Common.MA,Common.TE)))\
and (self.objNames[i]):
self.objNames[i] =\
Common.getLinkedObject(\
self.objNames[i],self.ipoTypeVals[i]).name
## ... or the opposite if datablocks names usage has been enabled.
else:
for i in range(0,self.entrCount):
if (not (self.ipoTypeVals[i]
in (Common.WO,Common.OB,Common.MA,Common.TE)))
and (self.objNames[i]):
self.objNames[i] = Object.Get(
self.objNames[i]).data.name
## Invoke function correcting the Ipo curves intervals.
elif event == self.E_CORRECT:
self.correctionMenu()
## Following options can be accessed only if thereis correctly loaded
## file.
elif self.isLoaded:
## Update of channel selection toggle
if event == self.E_CHAN_ENABLE:
self.channEnabled = not self.channEnabled
self.updateFilterCombos()
self.noteFilter()
## Update of instrument selection toggle
elif event == self.E_INSTR_ENABLE:
self.instrEnabled = not self.instrEnabled
self.updateFilterCombos()
self.noteFilter()
## Update of note selection toggle
elif event == self.E_NOTE_ENABLE:
self.notesEnabled = not self.notesEnabled
self.noteFilter()
## Update of increment’n’offset toggle
elif event == self.E_OFF_ENABLE:
self.orderEnabled = not self.orderEnabled
self.noteFilter()
## Update of time range selection toggle
elif event == self.E_RANGE_ENABLE:
self.rangeEnabled = not self.rangeEnabled
self.noteFilter()
## New selected channel value
elif (event == self.E_CHAN_CHOICE) and (self.channEnabled):
self.fChannVal = self.chanCombo.val
self.updateFilterCombos()
self.noteFilter()
## New selected instrument value
elif (event == self.E_INSTR_CHOICE) and (self.instrEnabled):
self.fInstrVal = self.instrCombo.val
self.updateFilterCombos()
self.noteFilter()
## New selected note value
elif (event == self.E_NOTE_CHOICE) and (self.notesEnabled):
self.fNoteVal = self.noteCombo.val
self.noteFilter()
## New increment or offset value
elif (event == self.E_OFF_CHOICE) and (self.orderEnabled):
self.fOrdVal[0] = self.offSpin.val
self.fOrdVal[1] = self.incSpin.val
self.noteFilter()
## New time range values
elif (event == self.E_RANGE_CHOICE) and (self.rangeEnabled):
self.fRangeVal[0] = self.rDownSpin.val
self.fRangeVal[1] = self.rTopSpin.val
if (self.fRangeVal[1]<self.fRangeVal[0]):
self.fRangeVal[0],self.fRangeVal[1] =
self.fRangeVal[1],self.fRangeVal[0]
self.noteFilter()
## Invoke creating new working copy of notes list
elif event == self.E_COPY:
self.notesCopy =
MidiFile.extractSelectedNotes(self.notesCopy)[:]
self.updateFilterCombos()
## Reset current working copy of notes list
elif event == self.E_CLEAR_COPY:
self.notesCopy = self.midi.noteList[:]
self.updateFilterCombos()
## Invoke synchronisation with current parameters
elif event == self.E_CREATE:
selectedNotes = MidiFile.extractSelectedNotes(self.notesCopy)
if not selectedNotes:
Draw.PupMenu(“Warning |No notes selected”)
return
eCount = 0
for i in range(0,self.entrCount):
if self.objNames[i] and self.ipoNames[i]:
if (self.obNamesEnabled)
and (not (self.ipoTypeVals[i]
in (Common.OB,Common.MA,Common.TE,Common.WO))):
name = Object.Get(self.objNames[i]).data.name
else:
name = self.objNames[i]
try:
Common.synchronise(selectedNotes,
self.ipoTypeVals[i],name,self.ipoNames[i],
self.leadKeys[i]-1,self.scaleEnabled[i],
self.holdEnabled[i],self.velVals[i],
self.relativeEnabled[i],self.pIpoNames[i]
,self.pScaleEnabled[i],self.initOffset)
eCount+=1
except SyncError, ex:
Draw.PupMenu(“Error |”+str(ex))
Draw.PupMenu(“Synchronisation completed |”+str(eCount)
+” entries processed”)
Draw.Redraw()
def drawLoadPanel(self):
"""Draw title bar and loading panel."""
BGL.glRecti(5,655,500,670)
BGL.glColor3f(0.1,0.1,0.1)
BGL.glRasterPos2i(10,658)
Draw.Text("MIDI Driver v.0.72 for Blender 2.49b","small")
BGL.glColor3f(0.75,0.75,0.75)
BGL.glRecti(5,620,500,650)
Draw.Button("Load MIDI:",self.E_LOAD,10,625,70,20,\
"Specify path to a MIDI file")
Draw.Label(Common.filename,90,625,330,20)
def drawFilterPanel(self):
"""Draw filter panel."""
BGL.glRecti(5,535,500,615)
self.chanToggle = Draw.Toggle("Channel",self.E_CHAN_ENABLE,10,590,70,\
20,self.channEnabled,"Enable channel selection")
self.instrToggle = Draw.Toggle("Instr",self.E_INSTR_ENABLE,10,565,70,\
20,self.instrEnabled,"Enable instrument selection")
self.noteToggle = Draw.Toggle("Note",self.E_NOTE_ENABLE,10,540,70,20,\
self.notesEnabled,"Enable note value selection")
self.orderToggle = Draw.Toggle("Order",self.E_OFF_ENABLE,250,565,70,\
20,self.orderEnabled,"Enable offset and increment")
self.rangeToggle = Draw.Toggle("Range",self.E_RANGE_ENABLE,250,590,\
70,20,self.rangeEnabled,"Enable time range")
self.chanCombo = Draw.Menu(self.chanEntr, self.E_CHAN_CHOICE,85,590,\
155,20,self.fChannVal, "Select channel")
self.instrCombo = Draw.Menu(self.instrEntr, self.E_INSTR_CHOICE,85,\
565,155,20,self.fInstrVal, "Select instrument")
self.noteCombo = Draw.Menu(self.noteEntr, self.E_NOTE_CHOICE,85,540,\
155,20,self.fNoteVal, "Select note")
self.offSpin = Draw.Number("",self.E_OFF_CHOICE,325,565,70,20,\
self.fOrdVal[0],0,self.orderCons,"Offset")
self.incSpin = Draw.Number("",self.E_OFF_CHOICE,400,565,70,20,\
self.fOrdVal[1],1,self.orderCons,"Increment")
self.rTopSpin = Draw.Number("",self.E_RANGE_CHOICE,325,590,70,20,\
self.fRangeVal[0],0,self.rangeCons,"From [ms]")
self.rDownSpin = Draw.Number("",self.E_RANGE_CHOICE,400,590,70,20,\
self.fRangeVal[1],0,self.rangeCons,"To [ms]")
self.copyButton = Draw.Button("Hide",self.E_COPY,250,540,70,20,\
"Hide unselected notes")
self.clCopyButton = Draw.Button("Unhide",self.E_CLEAR_COPY,325,540,70,\
20,"Unhide all notes")
def drawAnimPanel(self):
"""Draw animation control panel."""
BGL.glRecti(5,5,500,265)
for i in range(0,self.entrCount):
if self.ipoTypeVals[i] != Common.AR:
actPrefix = "IP:"
else:
actPrefix = "AC:"
if not self.dataExist(self.objNames[i],self.ipoTypeVals[i]):
self.objNames[i] = ""
if (self.obNamesEnabled) and (not (self.ipoTypeVals[i]\
in (Common.MA,Common.TE,Common.WO))):
obPrefix = "OB:"
else:
obPrefix = Common.typeAbbrev[self.ipoTypeVals[i]] + ":"
self.ipoTypeCombos[i] = Draw.Menu(self.ipoTypeEntries,\
self.E_ANIM_UPDATE,10,240-25*i,40,20,self.ipoTypeVals[i],\
"Datablock type")
self.objTBoxes[i] = Draw.String(obPrefix,self.E_ANIM_UPDATE,55,\
240-25*i,85,20,self.objNames[i],255,"Object or datablock name")
self.ipoTBoxes[i] = Draw.String(actPrefix,self.E_ANIM_UPDATE,145,\
240-25*i,85,20,self.ipoNames[i],255,"Source Ipo or Action name")
self.lKeySpins[i] = Draw.Number("",self.E_ANIM_UPDATE,235,\
240-25*i,30,20,self.leadKeys[i],1,self.leadKeyConstr[i],\
"Leading key")
self.scaleToggles[i] = Draw.Toggle("S",self.E_ANIM_UPDATE,270,\
240-25*i,20,20,self.scaleEnabled[i],"Enable source Ipo or\
Action scaling”)
self.holdToggles[i] = Draw.Toggle(“H”,self.E_ANIM_UPDATE,295,
240-25i,20,20,self.holdEnabled[i],“Hold leading key”)
self.velSpins[i] = Draw.Number(“”,self.E_ANIM_UPDATE,320,
240-25i,30,20,self.velVals[i],0,MidiFile.maxVelocity,
“Reference velocity for Y scaling”)
self.velToggles[i] = Draw.Toggle(“R”,self.E_ANIM_UPDATE,355,
240-25i,20,20,self.relativeEnabled[i],
“Relative/absolute velocity scaling”)
self.pIpoTBoxes[i] = Draw.String(actPrefix,self.E_ANIM_UPDATE,
380,240-25i,90,20,self.pIpoNames[i],255,
“Pause Ipo or Action name”)
self.pScaleToggles[i] = Draw.Toggle(“S”,self.E_ANIM_UPDATE,475,
240-25*i,20,20,self.pScaleEnabled[i],“Enable pause Ipo or
Action scaling”)
self.syncButton = Draw.Button(“Sync”,self.E_CREATE,10,10,60,20,
“Synchronise Ipos/Actions with notes”)
self.clearButton = Draw.Button(“Clear”,self.E_CLEAR_ANIM,80,10,60,20,
“Clear animation settings”)
self.quitButton = Draw.Button(“Quit”,self.E_EXIT,150,10,60,20,
“Exit this script”)
self.inOffSpin = Draw.Number(“”,self.E_INOFF,235,10,60,20,
self.initOffset,0,10000,“Initial offset”)
self.corrButton = Draw.Button(“Correct”,self.E_CORRECT,305,10,60,20,
“Correct Ipos/Actions pause intervals”)
self.obDaButton = Draw.Toggle(“OB/Data”,self.E_USE_OB,435,10,60,20,
self.obNamesEnabled,“Object names instead of datablocks”)
def createStructPanel(self):
"""Invoke refreshing of the structure displayer."""
if not self.isLoaded:
self.strDisp.refresh(None,False)
else:
self.strDisp.refresh(self.notesCopy,False)
def createInterface(self):
"""Establish script interface."""
BGL.glClearColor(0.6,0.6,0.6,1.0)
BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
BGL.glColor3f(0.75,0.75,0.75)
self.drawLoadPanel()
self.drawFilterPanel()
self.createStructPanel()
self.drawAnimPanel()
interf = Interface()
Draw.Register(
interf.createInterface,interf.strDisp.mouseHandler,interf.buttonEvents)
that’s a lot of work to rewrite this script to max script. The person who can do it has to have Blender, the knowledge of Blender Actions, python, and of course max script itself. I think the only a real enthusiast can take this task.
the another way is to find anyone who will do it for money (but I think it will be expensive).
yeah i guess the only thing is for me to learn Blender interface , the thing is i just need it for once its for my senior project its due to June 25 … i even wrote a mail to person who wrote the script and asked him but he didnt reply me … again thank you a lot : )
so basically you want someone to help you rip off someone else’s work so you can claim it as your own for your senior project…
well no im not gona rip off his work nor claim it my own senior project , coz im going on real time simulation and not just take his work and put the script on and say this is my work … what im looking for exactly is that a plug-in that can take sound wave of midi wave and turn in into signal and make the animation and if you bothered your self to open the web site link and read what he wrote which is
( This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. )
so don’t write just anything just to write.
thank you