# Processing, raspberry pi and camera

**URL:** <https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027>\
**Category:** Processing for Pi\
**Created:** [July 23, 2018, 9:16pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027 "2018-07-23T21:16:27Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 24, 2018, 9:38pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/21 "2018-07-24T21:38:36Z")

</div>

> [@neilcsmith](#):
>
> I tried to replicate the API in PraxisLIVE and gave up for another mechanism.

The standard way is to create a `@FunctionalInterface` so the library can call it back, like I did here: 🤪

> [@Sequencer firing multiple events/ or one step behind](https://discourse.processing.org/t/sequencer-firing-multiple-events-or-one-step-behind/1571/12):
>
> B/c there’s a slightly time loss during the time done is set to true and we check it ourselves, and only then we re-invoke start(), I don’t think class Countdown fits fully the requirements of your “sequencers”. sweat Just made a variant of it called Interval, where done is set to true over & over at a fixed period time. We now need to call Interval::intervalDone() in order to check whether the previous interval had been completed. As a bonus, in place or in addition to check Interval::inte…

> [@Sequencer firing multiple events/ or one step behind](https://discourse.processing.org/t/sequencer-firing-multiple-events-or-one-step-behind/1571/12):
>
> ## “Interval.java”:
> 
> ```auto
> @FunctionalInterface public interface Callback {
> void run();
> }
> 
> ```
> 
> ## “IntervalClass.pde”:
> 
> ```auto
> void createCallback() {
> interval.callback = new Interval.Callback() {
> @Override public void run() {
> fill(randomColor());
> }
> };
> }
> 
> ```

The interfaceless callback style is a much convenient way for Processing’s target coders though. 🙄

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [July 24, 2018, 9:49pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/22 "2018-07-24T21:49:16Z")

</div>

@GoToLoop I understand the principle of functional interfaces, and use them a lot (seen as we fully support Java 8). However, that particular callback has issues. The only way to replicate it is to make things markedly less efficient. IMO (as maintainer of the underlying bindings to GStreamer incidentally) it is the wrong approach.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 24, 2018, 9:58pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/23 "2018-07-24T21:58:43Z")

</div>

> [@neilcsmith](#):
>
> However, that particular callback has issues.

You’re right! I’ve included the callback feature as an alternative bonus to the Interval class.

It is indeed mutating the sketch’s canvas in another Thread via **fill()**!

Also, due to the way Processing calculates the `color`, the result value becomes corrupted when used by more than 1 Thread for the same PGraphics!

But b/c it’s a random `color`, it doesn’t matter whether the `color` calculation got wrong! 😄

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [July 24, 2018, 10:06pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/24 "2018-07-24T22:06:18Z")

</div>

@GoToLoop I’m talking about the movieEvent callback. It should be removed from the video library, not added to the Pi one!

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 24, 2018, 10:20pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/25 "2018-07-24T22:20:30Z")

</div>

As I remember, **movieEvent()** exists in the video library at least as far back as Processing 1.5.1; maybe it has always existed! 😜

If such craziness you’re asking actually happens, a big portion of existing sketches & tutorials will need to convert the slick **movieEvent()** to this ugly **available()** inside **draw()**! 😨

Not counting the other libraries should need to follow suit as well?! 😱

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [July 24, 2018, 10:57pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/26 "2018-07-24T22:57:15Z")

</div>

@GoToLoop this has nothing to do with anything else. I’m backing up gohai’s point that this particular callback is broken, not just for the reason he outlines, but because it also makes some other things very difficult or inefficient to implement. The video library is being updated to 2.x which should IMO be used to break it and make it better.

Anyway, enough going around in tangential circles! PM me if you want more info - pretty sure no-one else does. 😄

---

<div class="post-metadata">

**Author:** ![dan850](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dan850](https://discourse.processing.org/u/dan850)\
**Post date:** [July 24, 2018, 11:33pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/27 "2018-07-24T23:33:38Z")

</div>

Ok, I’m starting to sense some hostility in this thread. Obviously there are different approaches to handle any problem and some are more efficient than others. Lets try to be more respectful please.

---

<div class="post-metadata">

**Author:** ![dan850](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dan850](https://discourse.processing.org/u/dan850)\
**Post date:** [July 24, 2018, 11:41pm UTC](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027/28 "2018-07-24T23:41:18Z")

</div>



[Previous page](https://discourse.processing.org/t/processing-raspberry-pi-and-camera/2027.md?page=1)
