mouse position and app superpositions
@pluxite In linux and probably OSX you can use ggee's shell external to run xdotool getmouselocation
, just bang it with a metro. It's output is not fun to parse and limitations of ggee/shell mean it will be easier to just write a simple bash script like eval $(xdotool getmouselocation --shell), echo $X $Y
, call this script (using the full path) instead of the command itself and you get a simple list of xy coordinates. xdotool can also do other fun things like send mouse or keyboard commands to other windows or screens.
Edit: Not sure what I was thinking, the heat must be getting to me, much simpler. Separating two commands with a comma fails with ggee/shell since it sends them too quickly, the first command is not done when the second arrives and it also opens a new shell for the second command so even with a delay the $X and $Y variables will not be set in this new shell. Simple solution is just to replace the comma with &&, now it is a single command, the echo command is only executed if the first succeeds.
Ofelia Emscripten loading samples and images / converting number table to const char* or const float* array?
Now I can answer my own question
Loading an ofImage from a Lua table with pixel values from a .bmp works like that:
ofelia d $0-embindReceiveBitmap;
function embind_6(w, h, buf);
testImage:allocate(w, h, OF_IMAGE_COLOR_ALPHA);
print("bitmap size:", #buf, "bitmap width:", w, "bitmap height:", h);
local count = 0;
for i = 0, h - 1 do;
count = count + w -((w >> 2) << 2);
for j = 0, w - 1 do;
ofPushStyle();
testImage:setColor(j, h - i, ofColor(buf[(i * w + j) * 3 + 54 + count], buf[(i * w + j) * 3 + 55 + count], buf[(i * w + j) * 3 + 56 + count], 200));
ofPopStyle();
end;
end;
testImage:update();
end;
So, now it is possible with Emscripten and Ofelia to load and manipulate .bmp and .wav data in the internet...
And to control the patch with webMIDI (or just Java Script).
And to output (MIDI) data.
I seperated the MIDI and audio example:
https://pdsample.handmadeproductions.de/
https://pdmidi.handmadeproductions.de/
https://github.com/Jonathhhan/ofxOfelia
And I have some ideas and suggestions how to optimize this:
- It would be nice to make a better basic webMIDI Java Script interface template, which is easy to connect to any Emscripten Pure Data Patch.
- It would be really nice if the [ofelia define] object could return a value through the outlet if an embind function is called from C++ / Java Script.
At the moment the values are banged from a 10ms [metro], which is not optimal... - it would be great to directly load userdata from java script to Emscripten Ofelia, so the conversion to and from arrays would not be necessary.
- I would like to get rid of the security warnings, that appear because of webMIDI and webAudio...
- Another idea is to have the Ofelia Window fullscreen on a subpage that is controllable from a Java Script interfache on the main page.
- And, because I am not very experienced, it is possible that there are some bad mistakes in my code.
But I tried my best, and it seems to work.
Would be nice if somebody more experienced can have a look.
Of course there are some disadvantages compared to a desktop app:
- MIDI is not as tight (but quite good for the internet, still - it could be optimized).
- Loading a picture or a big sound file while audio is running drops the audio.
- It accepts only .bmp images.
- the size is more limited.
ofelia interface
Ofelia is a wrapper for openFrameworks that embed most of its functions and classes as Pd objects or Lua scripts. If you learn the logic and the syntax you could in theory program everything you can do in openFrameworks by just using Pd objects.
The problem is that while Gem has been designed with the final Pd user in mind, Ofelia is just a set functions. This means that it's much more flexible and powerful than Gem (where sometimes you are stuck with the way it was designed), but also that Ofelia in general ends up being very confusing and distracting for a beginner.
The solution for that would be to write better documentation and develop a set of abstractions to get stuff done quickly (like texturing on a 3D primitive, see here). This would have several advantages over Gem:
-
These abstractions could either be done with just Ofelia Pd objects or with Lua scripts. Lua scripts are actually a big thing, maybe the most important achievement of Ofelia. You are now basically able to write Pd «externals» using a high level scripting language that hides all the complexity to the user (memory management and stuff like that).
-
The graphic framework that Ofelia is built on has a very active community compared to Gem. This means that it is updated more often, uses updated software solutions and has a nice forum where a lot of questions have already been answered.
-
Once you learn how to use openFrameworks in Pd, you can move on and script your own objects, either in Pd with Lua or in openFrameworks itself.
TLDR; I believe that Ofelia is a very young project with many usability issues, but it has a lot of potential and might actually replace Gem if enough people will start using it.
Ofelia: Best workflow for Lua {arrays, of, things}
Ah, OK, -k
-- I had missed that.
Also interesting to be able to interface with pd arrays. That will be useful in some cases. The specific thing I was trying to do yesterday was to generate random positions for rectangles, and retain them so that they don't move on every ofDraw cycle. In that case it should be internal.
I'm thinking, though, that I might stick with external script files, because...
It dawned on me yesterday, when I got draw errors flooding the console for the umpteenth time, that instead of breaking and re-creating the connection between [ofDraw] and its descendents, I could stick a [spigot] in between and control it with a toggle. That led to the idea of a graph-on-parent abstraction (left inlet comes from [ofDraw] -> [ofRequire] -> etc., right inlet is a script path to read)... but AFAICS you can't programmatically open the contents of an [ofelia] box (no message you can send to it), so if I use this abstraction, then to edit the script, I would have to open the abstraction and then open the script... well, that's no fun.
It was also working quite well yesterday to edit the Lua code in Emacs and just click the [read...( box to update.
But thanks for -k
-- I had simply overlooked its significance. And it means, if I load the script from disk, it gets saved as a default script for next time.
hjh
Ofelia images -> variables
[ofRequire] loads the «M» variable from an [ofelia] object.
Let' say you have this [ofelia function] with name $0-script:
ofelia function $0-script;
M.x = 10;
You could use [ofRequire $0-script] to get the «M» variable defined in the [ofelia] object with name $0-script.
If you do this:
[ofRequire $0-script]
↓
ofelia function $0-another-script;
print(a.x);
This will print «10». What could be confusing is that I now use the «a» variable to access the «M» variable. That's because every float, symbol, pointer is received in the [ofelia function] with the name «a». Like:
[100(
↓
ofelia function $0-another-script;
print(a);
This will print the number «100». Now, since [ofImage] is actually an [ofelia define] object which cointains the variable M.image, if you require this script you will be able to access the image in an [ofelia function] using a.image, like this:
[...]
↓
[ofImage $0-nice-image]
and then:
[ofRequire $0-nice-image]
↓
ofelia function;
print(a.image:getWidth())
This will print the width of the image.
Hope this helps!
libpd in VCV Prototype?
Hi, Pure Data users/devs. I released VCV Prototype a few days ago which allows scripting languages to be used inside a module in VCV Rack. Currently only JavaScript is supported, but we hope to add about five more scripting backends eventually, maintained by developers who "adopt" each engine. Script writers add a process(block)
function, which is called to access each input, output, knob, switch, and RGB LEDs.
libpd (https://github.com/libpd/libpd) can be thought of as a scripting language backend, except instead of text files it loads Pure Data patches. If a libpd wrapper is added to VCV Prototype, Pure Data users can create patches with up to 6 inputs and 6 outputs and control it with knobs etc.
If any developers would like to adopt the libpd backend for VCV Prototype, you can run Pure Data patches inside VCV Rack. You can even edit the patch with Pure Data in another window, hit "save", and reload it in the VCV Prototype module. I've not sure how Pure Data patches work with regards to knobs and LEDs on VCV Prototype, but it might be possible. Let me know if anyone's interested in writing a LibpdEngine.cpp
file, or see https://github.com/VCVRack/VCV-Prototype#adding-a-script-engine for more details.
Source code: https://github.com/VCVRack/VCV-Prototype
VCV Library entry: https://vcvrack.com/plugins.html#VCV Prototype
ofelia sys_gui
@Jona So a lot can be done through sys:gui.
I had always thought scripting was limited because curly brackets could not be sent from Pd..... so is the ophelia sys-gui translating curved brackets?
And will the old [sys_gui] do the same?
I don't think the bind command can be made post start-up....... although Pd doesn't complain it doesn't seem to take effect......... https://puredata.info/docs/developer/PdStartupOrder
I just fell on this........... https://forum.pdpatchrepo.info/topic/7498/tk-widgets-tcl-to-sys-_gui
I had some success with making and opening pop-up widgets using a -plugin, but the patch from the OP looks much like the scripting in ofelia_sys_gui.zip.
It goes a little way to being able to make a catch-all script that could be fed parameters.
In the widget demo included in vanilla since 0.46.7 you have an example that places pictures in tk widgets.
It needs some of the scripting from the demo script, or it needs to be modified to work without the demo script running.
A pop-ed up widget takes control from the Pd GUI. You need to be careful that you catch any mistaken closure by the window-close button or Pd loses contact with wish, hangs and cannot be closed.
The demo scripts contain the catch.
David.
webpd slider onchange
I`ve just started using webpd and I would be happy if someone showed me how to properly write a very simple HTML & javascript code connected to the pd patch, which has a slider that fires the moment when the value of the element is changed.
<!doctype HTML>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="../js/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="../js/webpd-latest.js"></script>
<script type="text/javascript" src="../js/elindit.js"></script>
</head>
<body>
<button id="startButton">Start</button>
<div id="controls">
<form>
<input type="text" id="freqInput" />
<input type="submit" value="Set frequency" />
</form>
</div>
<script type="text/javascript">
webPdLali.init()
$('form').submit(function(event) {
event.preventDefault()
Pd.send('freq', [parseFloat($('#freqInput').val())])
})
var patch
$.get('pd/main.pd', function(mainStr) {
// Loading the patch
patch = Pd.loadPatch(mainStr)
webPdLali.patchLoaded(mainStr)
})
</script>
</body>
</html>
Getting Shelly 1 device to work with PureData and MobMuPlat
Getting Shelly 1 device to work with PureData and MobMuPlat
Here's the Pd along with a picture attached of how to get the Shelly 1 to be turned on using Pd Vanilla. Here's a link to the product https://shelly.cloud/shelly1-open-source/ . You could also use mrpeach which would make it easier but I could only use Pd Vanilla.
All credit goes to the people on the Pd List IOhannes m zmölnig, Jack, Mrpeach, the Shelly 1 facebook forum and a host of others
The Pd for turning on and off a couple of Shelly 1's which are connected to a musical Tesla coil, a pump, and a ultrasonic mister.
I'll be using MobMuPlat to control all of this from my tablet this will allow my laptop to do all the CPU sound generating intensive stuff. Someone made a good tutorial that explains this links below.
I'll place the completed project on (at the moment the first test version is up but I'll be putting a different design up next )
https://stillpointx.wordpress.com/research/modulated-plasma/
Here's the pd file
test_netsend_shelly1_on_off_toggle.pd
can load libraries with the GUI but not without - Raspberry Pi
Hey David.
Thanks so much for your response. After a crazy amount of hours I have worked out a way to get it all to work together. I tried every which way of creating flags to get those libraries to load and ultimately I gave up. I ended up installing Purr-data pd-l2ork which seems to be generally more stable than vanilla and happens to load all of my libraries automatically on start regardless of whether they're needed or not. The issue I ran into then was that on RPi, you need jackd to route MIDI. Unfortunately, jackd2 doesn't run on raspberry pi. I fought with it for a while, tried some tricks from forum posts that say to use jack 1.0.8 but I still couldn't get it to work. I use alsa aconnect on some other projects running on pi and I thought I would give it a try. Though the device port numbers change every time you boot up depending on what peripherals you're using, I found that you can also aconnect using the device name. The trick then became trying to find a way to run not one script on startup but two scripts. After fighting with /etc/rc.local and crontab for some hours, I found that even when I got both things to run, I ran into all kinds of alsa errors, mainly the one where PCM cannot open, blah blah blah. So I've been sitting in front of Pd for so long that I'm starting to have dreams about Pd and half awake, I wondered if a) its possible to specify preference settings with objects and b ) if its possible to run a shell script from an object in PD. Then I only have to run the one script on start. I found an object {shell] that allowed me to run my aconnect stuff in the shell after loading my patch. Then I saw a brilliant post that explained how to change preferences using [r pd] and [print] . If you make changes to your preferences, the pd window spits out some numbers that specify the setting you just saved. Then you can copy and paste those values into a ;pd message and change your preference with a loadbang. I had to stagger the different messages with various [delay] objects but the thing works.