Triggering solution refresh from a custom component? - Grasshopper2024-03-28T16:50:08Zhttps://www.grasshopper3d.com/forum/topics/triggering-solution-refresh?commentId=2985220%3AComment%3A169903&feed=yes&xn_auth=noMark,
Here's my code.
https…tag:www.grasshopper3d.com,2017-07-06:2985220:Comment:17798522017-07-06T19:48:29.755ZEric Anastashttps://www.grasshopper3d.com/profile/EricAnastas
<p></p>
<p>Mark,</p>
<p></p>
<p>Here's my code.<br/><br/></p>
<p><a href="https://bitbucket.org/ericanastas/grasshopper-midi" target="_blank">https://bitbucket.org/ericanastas/grasshopper-midi</a></p>
<p><br/>It's been almost 7 years since I've looked at this, so I doubt I can be much more help. I never did get anywhere with the continuous update problem.</p>
<p></p>
<p>- Eric Anastas</p>
<p></p>
<p></p>
<p></p>
<p>Mark,</p>
<p></p>
<p>Here's my code.<br/><br/></p>
<p><a href="https://bitbucket.org/ericanastas/grasshopper-midi" target="_blank">https://bitbucket.org/ericanastas/grasshopper-midi</a></p>
<p><br/>It's been almost 7 years since I've looked at this, so I doubt I can be much more help. I never did get anywhere with the continuous update problem.</p>
<p></p>
<p>- Eric Anastas</p>
<p></p>
<p></p> I actually somewhat got a mid…tag:www.grasshopper3d.com,2017-07-06:2985220:Comment:17796012017-07-06T16:23:44.784ZJed Lankitushttps://www.grasshopper3d.com/profile/JedLankitus
<p>I actually somewhat got a midi controller input to work, but it is specific to my controller. If you would like we could team up and put out a quality midi plugin that is more universal.</p>
<p></p>
<p>I was hoping to put out an open source midi plugin so people could add presets for their own controllers and eventually we would have most of the mainstream ones covered</p>
<p>I actually somewhat got a midi controller input to work, but it is specific to my controller. If you would like we could team up and put out a quality midi plugin that is more universal.</p>
<p></p>
<p>I was hoping to put out an open source midi plugin so people could add presets for their own controllers and eventually we would have most of the mainstream ones covered</p> Hi Eric, I'd love to see this…tag:www.grasshopper3d.com,2017-07-06:2985220:Comment:17796312017-07-06T15:15:23.976ZMarc Syphttps://www.grasshopper3d.com/profile/MarcSyp
<p>Hi Eric, I'd love to see this code as well. I'm not sure if my plugin project needs the invoke methods yet, but if I can't solve my crashing problems I'm willing to try. Would love a sample in the GH context to help guide me.</p>
<p></p>
<p>Also curious to hear how your tests (on longer solves and continuous updates) turned out!</p>
<p></p>
<p>Thanks!</p>
<p></p>
<p>Marc</p>
<p></p>
<p>Hi Eric, I'd love to see this code as well. I'm not sure if my plugin project needs the invoke methods yet, but if I can't solve my crashing problems I'm willing to try. Would love a sample in the GH context to help guide me.</p>
<p></p>
<p>Also curious to hear how your tests (on longer solves and continuous updates) turned out!</p>
<p></p>
<p>Thanks!</p>
<p></p>
<p>Marc</p>
<p></p> Hey Eric, could I see this co…tag:www.grasshopper3d.com,2017-05-21:2985220:Comment:17552892017-05-21T22:30:48.126ZJed Lankitushttps://www.grasshopper3d.com/profile/JedLankitus
<p>Hey Eric, could I see this code?</p>
<p>Hey Eric, could I see this code?</p> I am also trying to find out…tag:www.grasshopper3d.com,2011-08-26:2985220:Comment:3940232011-08-26T20:16:20.150ZDawn Groveshttps://www.grasshopper3d.com/profile/DawnGroves
<p>I am also trying to find out how to do this? If you have figured it out please let me know as I have an event coming up soon that I need it for.</p>
<p> </p>
<p>Thanks!</p>
<p> </p>
<p>Dawn</p>
<p><a href="http://www.lmg.net/" target="_blank">Show Technology</a></p>
<p>I am also trying to find out how to do this? If you have figured it out please let me know as I have an event coming up soon that I need it for.</p>
<p> </p>
<p>Thanks!</p>
<p> </p>
<p>Dawn</p>
<p><a href="http://www.lmg.net/" target="_blank">Show Technology</a></p> Schedules a new solution some…tag:www.grasshopper3d.com,2011-03-01:2985220:Comment:1729142011-03-01T10:08:44.875ZDavid Ruttenhttps://www.grasshopper3d.com/profile/DavidRutten
<p>Schedules a new solution sometime in the foreseeable future. You can specify how long Grasshopper should wait before starting the next solution. This is what the Timer object calls.</p>
<p> </p>
<p>You can also supply a call-back so you'll get informed just before the new solution kicks off (so you can gather additional data or expire certain objects or whatever).</p>
<p> </p>
<p>--</p>
<p>David Rutten</p>
<p>david@mcneel.com</p>
<p>Poprad, Slovakia</p>
<p>Schedules a new solution sometime in the foreseeable future. You can specify how long Grasshopper should wait before starting the next solution. This is what the Timer object calls.</p>
<p> </p>
<p>You can also supply a call-back so you'll get informed just before the new solution kicks off (so you can gather additional data or expire certain objects or whatever).</p>
<p> </p>
<p>--</p>
<p>David Rutten</p>
<p>david@mcneel.com</p>
<p>Poprad, Slovakia</p> So, what does GH_Document.Sch…tag:www.grasshopper3d.com,2011-03-01:2985220:Comment:1727172011-03-01T00:56:19.188ZEric Anastashttps://www.grasshopper3d.com/profile/EricAnastas
So, what does GH_Document.ScheduleSolution() do?
So, what does GH_Document.ScheduleSolution() do? Yes I did end up invoking met…tag:www.grasshopper3d.com,2011-02-26:2985220:Comment:1708262011-02-26T10:57:14.045ZEric Anastashttps://www.grasshopper3d.com/profile/EricAnastas
<p>Yes I did end up invoking methods as you suggested. When midi events occur on the working thread I invoke a SetValue() method on my components to update their value, and then I invoke the ExpireSolution(false) on the component to mark it as needing to be re-solved. At this point my code either starts or restarts a timer, which when complete invokes NewSolution(false).</p>
<p> </p>
<p>My idea with the timer was that if the user moved the knob very quickly, I would want Grasshopper to try to…</p>
<p>Yes I did end up invoking methods as you suggested. When midi events occur on the working thread I invoke a SetValue() method on my components to update their value, and then I invoke the ExpireSolution(false) on the component to mark it as needing to be re-solved. At this point my code either starts or restarts a timer, which when complete invokes NewSolution(false).</p>
<p> </p>
<p>My idea with the timer was that if the user moved the knob very quickly, I would want Grasshopper to try to solve on the value from the last knob position not the first new position it saw.</p>
<p> </p>
<p>I used a reference to the ActiveCanvas through the GH_InstanceServer to call Invoke on. For example here's the code I used to expire a component.</p>
<blockquote><p>Grasshopper<span class="p">.</span>GH_InstanceServer<span class="p">.</span>ActiveCanvas<span class="p">.</span>Invoke<span class="p">(</span><span class="k">new</span> Action<span class="p"><</span><span class="kt">bool</span><span class="p">>(currentGHComponent</span><span class="p">.</span>ExpireSolution<span class="p">),</span> <span class="k">new</span> <span class="kt">object</span><span class="p">[]</span> <span class="p">{</span> <span class="k">false</span> <span class="p">});</span></p>
</blockquote>
<p>I just got this working right before I left the office tonight, so I didn't have a lot of time to test it. As you can see from the video I was testing a solution that can be solved almost instantly. On Monday I plan to test it with a solution that takes longer to solve. I'm curious what happens if I keep turning the knob on the controller while the solver is already running. I'm thinking the additional invokes to NewSolution() will stack up in the GUI message queue and end up running immediately after the current solution finishes one after the other. I'm not sure though. If that's the case I'll probably need to track if a NewSolution() invoke has already been sent out, and whether it has completed (SolutionEnd event fires) before making additional calls to NewSolution().</p>
<p> </p>
<p>I have the project up on a SVN server if your interested in checking out the code.</p>
<p> </p> Cool! So did you end up invok…tag:www.grasshopper3d.com,2011-02-26:2985220:Comment:1704922011-02-26T09:20:51.826ZDavid Ruttenhttps://www.grasshopper3d.com/profile/DavidRutten
<p>Cool! So did you end up invoking any methods? What winforms object did you invoke them on?</p>
<p> </p>
<p>Also, what happens when your events are coming in quicker than Grasshopper can handle them. Do they just stack up forever or are you dropping events if you feel you're getting too far ahead?</p>
<p> </p>
<p>--</p>
<p>David Rutten</p>
<p>david@mcneel.com</p>
<p>Poprad, Slovakia</p>
<p>Cool! So did you end up invoking any methods? What winforms object did you invoke them on?</p>
<p> </p>
<p>Also, what happens when your events are coming in quicker than Grasshopper can handle them. Do they just stack up forever or are you dropping events if you feel you're getting too far ahead?</p>
<p> </p>
<p>--</p>
<p>David Rutten</p>
<p>david@mcneel.com</p>
<p>Poprad, Slovakia</p> As usual David, thanks for th…tag:www.grasshopper3d.com,2011-02-26:2985220:Comment:1708142011-02-26T05:47:11.071ZEric Anastashttps://www.grasshopper3d.com/profile/EricAnastas
<p>As usual David, thanks for the easy to understand and comprehensive response. I've dabbled in multithreading with a couple of my programs. So Invoke and BeginInvoke are not entirely new to me, but I'm far from an expert.</p>
<p> </p>
<p>Anyway I was able to get a really rough version of my custom MIDI components working with your help. See the video below:</p>
<br></br>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" height="290" width="400"><param name="allowfullscreen" value="false"></param><param name="allowscriptaccess" value="never"></param><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=20395817&server=vimeo.com&show_title=1&show_byline=1&show_portrait=1&color=00ADEF&fullscreen=1&autoplay=0&loop=0"></param><embed allowfullscreen="false" allowscriptaccess="never" height="290" src="http://vimeo.com/moogaloop.swf?clip_id=20395817&server=vimeo.com&show_title=1&show_byline=1&show_portrait=1&color=00ADEF&fullscreen=1&autoplay=0&loop=0" type="application/x-shockwave-flash" width="400" wmode="opaque"></embed> …<param name="wmode" value="opaque"></param></object>
<p>As usual David, thanks for the easy to understand and comprehensive response. I've dabbled in multithreading with a couple of my programs. So Invoke and BeginInvoke are not entirely new to me, but I'm far from an expert.</p>
<p> </p>
<p>Anyway I was able to get a really rough version of my custom MIDI components working with your help. See the video below:</p>
<br/>
<object height="290" width="400" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"><param name="allowfullscreen" value="false"></param><param name="allowscriptaccess" value="never"></param><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=20395817&server=vimeo.com&show_title=1&show_byline=1&show_portrait=1&color=00ADEF&fullscreen=1&autoplay=0&loop=0"></param><embed wmode="opaque" height="290" width="400" src="http://vimeo.com/moogaloop.swf?clip_id=20395817&server=vimeo.com&show_title=1&show_byline=1&show_portrait=1&color=00ADEF&fullscreen=1&autoplay=0&loop=0" allowscriptaccess="never" allowfullscreen="false" type="application/x-shockwave-flash"></embed>
<param name="wmode" value="opaque"></param></object>
<br/>
<p> </p>
<p> </p>
<p> </p>