[Closed] first try at dot net. need a bit nof help
I posted up a midi script on the autodesk forums sometime back
http://discussion.autodesk.com/thread.jspa?messageID=5722727�
, in one of the replys someone had posted up a script using dot net to read a midi file so Im trying to get this to work but I dont know anything about dot net programing , Im using this dll
http://www.gotdotnet.com/community/usersamples/details.aspx?sampleguid=89cde290-5580-40bf-90d2-5754b2e8137c
heres the script
myAssembly = dotNetClass "System.Reflection.Assembly"
myAssembly.loadfrom scriptpath+"[\\midi\Toub.Sound.Midi.dll](file://midi/Toub.Sound.Midi.dll)"
-- midiEC = dotnetobject "Toub.Sound.Midi.MidiEventCollection"
-- midiME = dotnetobject "Toub.Sound.Midi.MetaMidiEvent"
midi = dotnetClass "Toub.Sound.Midi.MidiSequence"
midifile = midi.import scriptpath+"[\\midi\SgtPepper.mid](file://midi/SgtPepper.mid)"
-- showproperties midifile
i = midifile.item 0
--showproperties i
ev = i.events
--showproperties ev
--Set the time as we go through the events
deltaTime = 0
--Go through the events
for x = 0 to (ev.count - 1) do
(
evnt = ev.item x
str = (evnt.tostring())
--format "% %
" x str
tempo = .1
case of
(
--Tempo Event
(matchpattern str pattern:"Tempo*"):
(
format "% %
" x str
--given Tempo appears to be in ms/b
--60,000,000 ms/minute /
tempo = 60000000.0/evnt.value
tempo = tempo /100.0
format "Tempo: %
" tempo
)
--Note Event
(matchpattern str pattern:"NoteOn*"):
(
--format "% %
" x str
deltaTime = deltaTime + evnt.deltaTime
format "Time:% NoteNum: % Velocity:%
" deltaTime evnt.note evnt.Velocity
ctrl = undefined
case of
(
(evnt.note == 20):ctrl=$Sphere01.position.controller.z_position.controller
(evnt.note == 31):ctrl=$Sphere02.position.controller.z_position.controller
(evnt.note == 37):ctrl=$Sphere03.position.controller.z_position.controller
)
--To key objects do this
/*
if ctrl !=undefined then
(
animate on
(
at time (((deltatime/10) - 1) as time ) ctrl.value = ctrl.value
at time ((deltatime/10) as time ) ctrl.value = (evnt.velocity)/10
)
)
*/
ctrl.value = (evnt.velocity)/10
redrawViews()
sleep tempo
)
)
--showproperties evnt
--evnt.value
)
and heres the error Im getting
dotNetClass:System.Reflection.Assembly
– Runtime error: No method found which matched argument list
undefined
– Unknown property: “import” in undefined
– No ““showProperties”” function for undefined
– Unknown property: “item” in undefined
– Unknown property: “events” in undefined
0
– Error occurred in anonymous codeblock
– Frame:
– Unknown property: “count” in undefined
OK
I have asked on the autodesk forum but I know a few of you guys here know dotnet so I hope you can help .
what does this mean “No method found which matched argument list” it seems the script is loading the dll so why am I getting this error ?
got to go out to work but will look at this post when i get home tonight.
thanks for reading
Thanks for reading
Hi,
from what I see the variable scriptpath is not initialized:
and you you need a double \ in the path (because of ’ ’ wich maxscript sees as a tab character, so you are betterchanging them to ‘/’
also, you need to put the expressions in between ()
scriptpath=getdir #scripts
myAssembly.loadfrom (scriptpath + “/midi/Toub.Sound.Midi.dll”)
midifile = midi.import (scriptpath + “/midi/SgtPepper.mid”)
hope this helps
You can use:
dotNet.loadAssembly (scriptpath + "/midi/Toub.Sound.Midi.dll")
Instead of using System.Reflection.Assembly class.
Also, .Net uses lot of memories so as written in the Reference you can force garbage collection / memory cleaning of all unused managed variables :
dotNetGC = dotnetclass "System.GC"
dotNetGC.collect()
gc()