Giter Club home page Giter Club logo

loaf's Introduction

loaf: lua, osc, and openFrameworks

loaf icon

Copyright (c) Dan Wilcox 2016-2020

GPL v3

For information on usage and redistribution, and for a DISCLAIMER OF ALL WARRANTIES, see the file, "LICENSE.txt," in this distribution.

loaf website: danomatika.com/code/loaf

DESCRIPTION

cut off a slice of something nice

loaf is an interpreter for openFrameworks which allows you to write OF applications in the Lua scripting language. This means you can quickly create using openFrameworks but without having to compile C++ or use a heavy IDE like Xcode or Visual Studio. A built-in OSC (Open Sound Control) server enables loaf to communicate natively with other creative coding and music applications over a network connection. Additionally, a built-in Syphon server allows for streaming loaf's screen output to visual applications on the same macoS system.

Is loaf a replacement for building a native C++ application?

No. If you need to be able to include openFrameworks addons, stay with C++ for now.

So what is it for?

loaf is intended as a simple sandbox for sketching using the openFrameworks core API with a live-coding feel: make changes and see the result quickly. No compiling, no low level errors, just the basics. Think of loaf kind of like Processing without the run button.

loaf workflow

Background

loaf is the result of the author's need for a visual coding tool for performance that can run almost anywhere and communicate with tools such as Pure Data or Max MSP. Using Lua allows for loaf to react to script changes so the process of creation matches that of a dataflow environment like Pd. The native inclusion of OSC allows for coupling of loaf and other creative applications for experimentation.

loaf's design is influenced by the LÖVE Lua game engine and the Fluxus live-coding environment. It is essentially the 3rd (or 4th) iteration of a similar tool for the author's robotcowboy wearable performance project: rc-visual, originally a C++ application using SDL which read XML scene descriptions and blitted to the console framebuffer. loaf is now used as the interpreter for rc-visual which is implemented completely in Lua and works with its controller input complement, joyosc.

QUICK START

Download a release build from docs.danomatika.com/releases/loaf (currently macOS only) or build loaf after git cloning from Github

Once you have a copy of loaf, drag the loaf.app into your Applications folder (macOS) or simple run it from the loaf folder by double-clicking.

Note: A more comprehensive User Guide will be added in the future.

Basic usage

  • Drag a Lua script or folder with a main.lua onto loaf to run it
  • Either save the script somehow (in a text editor) and/or use MOD+R in loaf to reload it automatically
  • Toggle fullscreen with MOD+F
  • Script errors are shown on the app window and on the console if you run it in a terminal application
  • Prints are shown in the console (useful for debugging)
  • The current script can be cleared with SHIFT+MOD+R

The MOD key depends on the platform: macOS COMMAND, Windows/Linux CONTROL.

Scripts, Folders, and Data Path

loaf supports opening Lua scripts (.lua) and folders which contain a main.lua file. The folder option is useful for project encapsulation. Any data file paths are automatically relative to the script's parent folder, ie. loading an image from script.lua in the following project layout:

project/script.lua
project/image.jpg

works like this:

image = of.Image()
image:load("image.jpg")

This also means Lua's require function works as expected when importing other Lua scripts or modules into the main script.

Using Lua and OF

A quick overview of using Lua and the Lua bindings for openFrameworks can be found in the ofxLua readme.

The best place to start is to look at the examples included with loaf zip and on the loaf Github repo.

There are also simple syntax lists for each of the built-in Lua bindings modules: of, osc, loaf, and syphon. These can be found in doc/modules and are a good place to start for creating auto-completion files for you favorite text editor.

Syphon Support

On macOS, loaf includes support for Syphon via a built-in server and a Lua "syphon" module with bindings for the ofxSyphonClient, ofxSyphonServer, and ofxSyphonServerDirectory classes.

Similar to the built-in OSC sender and receiver instances, the Syphon server can be accessed via loaf module Lua functions:

  • loaf.startSyphon(): start server to publish screen each frame
  • loaf.stopSyphon(): stop server
  • loaf.setSyphonName(): set server name
  • loaf.isSyphonPublishing(): is the server publishing right now?
  • loaf.getSyphonServer(): get the built-in server instance

Note: Make sure to call loaf.getSyphonServer() only after starting the server, otherwise the instance will not exist, i.e returns as "nil."

Additionally, the "syphon" module allows for using Syphon directly in Lua scripts. See examples/tests/syphon.lua.

Setting Window Size

By default, loaf starts as a 640x480 window. If you want a different resolution or to go fullscreen, you can simply call the corresponding OF functions in your script:

function setup()
    of.setWindowShape(1024, 768) -- resizes the window, like Processing size()
    of.setFullscreen(true) -- go fullscreen! also the -f commandline option
end

loaf Commandline Options

loaf has a number of options which can be set when running it from the commandline, the most basic being a script to run:

loaf path/to/script.lua

Use -h to print a usage help print:

Usage: loaf [options] [PATH [args]]

  lua, osc, and openFrameworks

Options:
  -h, --help       print usage and exit
  --version        print version and exit
  -a, --address    OSC host address to send to (default: localhost)
  -p, --port       OSC port to send to (default: 8880)
  -l, --listen     OSC port to listen on (default: 9990)
  -s, --start      start listening for OSC messages
  -f, --fullscreen start in fullscreen
  -i, --ignore     ignore script changes
  -e, --exit       exit after script error
  -r, --reload     reload timeout in secs after a script error
  --gl             try to set gl version to use ie. "4.1"
  --syphon-name    Syphon server name (default: screen)
  --syphon         start streaming screen with Syphon (macOS only)
  -v, --verbose    verbose printing

Arguments:
  PATH             optional lua script or folder to run
  args...          arguments to pass to the lua script

You can also pass arguments to the script itself by placing them after the script path:

loaf script.lua hello 123

See the argument test script for more details: examples/tests/arg.lua

macOS Terminal alias

On macOS, you can run a .app from Terminal by calling the binary hidden inside the application bundle:

/Applications/loaf.app/Contents/MacOS/loaf -h

To make this less cumbersome, you can add an alias in your .bash_profile:

alias loaf="/Applications/loaf.app/Contents/MacOS/loaf"

which allows you to call loaf with just the short alias instead:

loaf -h

Libraries

As loaf contains the Lua embedded scripting language, pure Lua libraries will work fine with it. Pre-compiled loadable Lua modules will also work as long as they are found within the require search path.

Also, a set of loaf-oriented Lua libraries is available in the loaf-ingredients repository.

BUNDLING INTO STAND-ALONE APPS

As of loaf 1.6.0, loaf projects can be "bundled" into stand-alone applications. If a "main.lua" script is found on startup, it will be used by default:

  • Windows / Linux: "data" folder next to loaf executable, ./data/
  • macOS: "data" folder within a macOS .app bundle, ../Resources/data/

The loaf executable can also be renamed.

macOS

A macOS .app bundle is basically a folder structure presented by Finder as an "application." It contains the application executable, dependent libraries, and resource files. This structure can be created & modified to make your own application which can then be distributed to run on other macOS systems.

To facilitate creating a stand-alone .app from a loaf project, the scripts/make_osxapp.sh shell script can make a copy of an existing loaf.app and use it to create a new application by copying the loaf project Lua scripts and data files inside the bundle. Additionally, it can modify metadata such as the application name, version string, and icon.

For example.

./scripts/make_osxapp.sh -l bin/loaf.app ~/Desktop/loaf-project LoafProject

will create a LoafProject.app using the files in ~/Desktop/loaf-project.

See the make_osxapp.sh help output for more info:

./scripts/make_osxapp.sh --help

BUILDING LOAF

To build loaf, you will need a copy of openFrameworks: http://openframeworks.cc/download/

loaf requires the following addons:

  • ofxLua
  • ofxOsc (included with openFrameworks)
  • ofxSyphon (optional, macOS-only)

Project files for building loaf on Windows or Linux are not included so you will need to generate them for your operating system and development environment using the OF ProjectGenerator which is included with the openFrameworks distribution.

To (re)generate project files for an existing project:

  • Click the "Import" button in the ProjectGenerator
  • Navigate to the base folder for the project ie. "loaf"
  • Click the "Update" button

If everything went Ok, you should now be able to open the generated project and build/run the example.

macOS

Open the Xcode project, select the "loaf Release" scheme, and hit "Run". Once built, the loaf.app is found in the bin directory.

For a Makefile build with Syphon (default), build and run on the terminal:

make ReleaseLoaf
make RunRelease

If not using Syphon, use the default make target:

make Release

Updating Xcode Project After Generation

If the project is (re)generated using the OF ProjectGenerator, the openFrameworks-Info.plist file will be overwritten and these changes can be reversed with:

git checkout openFrameworks-Info.plist

Enabling Syphon Support

Syphon support must be enabled as a compile-time option using the LOAF_USE_SYPHON C++ define.

  • Select loaf project in the Xcode file tree
  • Select loaf under PROJECT list and Build Settings tab
  • Find Other C++ flags and add: -DLOAF_USE_SYPHON

If doing a Makefile build, use the additional targets which will also install the Syphon framework into loaf.app: DebugLoaf & ReleaseLoaf.

Fixing Unknown option "NSDocumentRevisionsDebugMode"

If running the project does nothing except for showing the following console output:

Unknown option "NSDocumentRevisionsDebugMode"

Edit the Debug and Release schemes and uncheck "Document Versions" in Run->Options tab.

Linux

To build and run on the terminal:

make
make run

Windows

Instructions for Visual Studio to be added here. Contributions are welcome.

DEVELOPING

You can help develop ofxLua on GitHub: https://github.com/danomatika/loaf

Create an account, clone or fork the repo, then request a push/merge.

If you find any bugs or suggestions please log them to GitHub as well.

loaf's People

Contributors

danomatika avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

loaf's Issues

option to not autopublish screen on syphon

this line:

syphon.publish();

autopublishes the screen on every draw call
i like the idea of having a persistent syphon server running even if i make errors in my lua scripting, but i also like the ability to choose which textures i want to publish.

i suggest to let an commandline option decide if the screen should be autopublished or not.

then i would be able to draw all my content in an fbo with huge size and publish it to builtin syphon serverloaf.getSyphonServer():publishTexture(myFbo:getTexture()) as well as draw a miniature preview on screen.

in short i wouldnt be bound by the app screen size.

I REEEEEALLY LIKE THIS PROJECT by the way, BIG THANKS!

Building on Linux

Long time Processing & Lua user, but new to OF; this project looks great!

When trying to build loaf on Ubuntu 14.04 (gcc-4.9), I ran into this error:

In file included from /usr/include/X11/Xlib.h:44:0,
                 from /usr/include/GL/glx.h:30,
                 from OF/libs/openFrameworks/utils/ofConstants.h:184,
                 from OF/libs/openFrameworks/utils/ofFileUtils.h:3,
                 from loaf-1.3.0/src/CommandLine.cpp:26:
loaf-1.3.0/src/options/optionparser.h:889:20: error: expected unqualified-id before numeric constant
   static ArgStatus None(const Option&, bool)
                    ^
In file included from loaf-1.3.0/src/CommandLine.cpp:30:0:
loaf-1.3.0/src/options/Options.h:365:34: error: expected unqualified-id before ‘const’
    static option::ArgStatus Bool(const option::Option& option, bool msg) {
                                  ^
loaf-1.3.0/src/options/Options.h:365:34: error: expected ‘)’ before ‘const’
loaf-1.3.0/src/CommandLine.cpp:113:1: error: expected ‘}’ at end of input
 }
 ^

None and Bool clash with preprocessor macros from X.h so my workaround was to change CommandLine.cpp:

#include "ofFileUtils.h"
#undef None
#undef Bool
#include "ofLog.h"
#include "Options.h"

How to access C++ vectors in Loaf

I'm trying to access a vector containing the list of vertices of a polyline. I can run the following script and get the results in my Lua variable, but I don't know how to access this «userdata».

local line = of.Polyline()
local vertices = line:getVertices()

I tried many combinations to read the vector<glm::vec3> type but I only get this error:

[ error ] loaf: script.lua: attempt to index a userdata value (local 'vertices')

Is there a way to access this kind of data?

Notes for building on RasPi

Spent a bunch of time trying to get loaf to compile/run on my RasPi 4 last night and wanted to write up some notes for you.

In config.make PROJECT_EXCLUSIONS would not work properly and syphonBindings.cpp would try to compile every time.
PROJECT_EXCLUSIONS = $(PROJECT_ROOT)/src/bindings/syphonBindings.cpp

From searching the forum it seems that PROJECT_EXCLUSIONS will only work reliably for a directory (?)

So - I created a directory called exclude and moved syphonBindings.cpp to that directory and excluded that. Not an ideal solution, but wasn't sure how else to exclude that file.

config.make additions (which I suppose could go in an if Linux block at some point):

PROJECT_CFLAGS = -I$(OF_ROOT)/addons/ofxOsc/libs/oscpack/src/
PROJECT_CFLAGS += -I$(OF_ROOT)/addons/ofxOsc/libs/oscpack/src/osc
PROJECT_CFLAGS += -I$(OF_ROOT)/addons/ofxOsc/libs/oscpack/src/ip
PROJECT_CFLAGS += -I$(OF_ROOT)/addons/ofxOsc/libs/oscpack/src/ip/posix

PROJECT_EXCLUSIONS = $(PROJECT_ROOT)/src/bindings/exclude
PROJECT_EXCLUSIONS += $(OF_ROOT)/addons/ofxOsc/libs/oscpack/src/ip/win32

Then I commented out the ifeq Darwin block.

Then... In Syphon.cpp I had to change the last line to this to get it to compile

ofxSyphonServer *Syphon::getServer() {
	return server;
}

but after all that, I'm running. :)

Open loaf from VS code and get console output

Hello, wondering if there's a way to launch loaf from VS code and get console output there too. I can dig into the Package Contents 'folder' of the app and launch a terminal window from there, but it's kind of cumbersome. Looking for a way to have it all in Code. Thanks!

OSC typo in helloword.lua

In the helloword.lua script, I had to change these conditions (lines 43 and 45)
if message.address == "/circle/x"
in

if message:getAddress() == "/circle/x"

Strange behaviour of ofPixels:getColor() on grayscale images

ofPixels:getColor() returns an RGBA value instead of a single value, even if allocated using the of.PIXEL_GRAY format. All the other settings are updated properly.

local pixels = of.Pixels()
pixels:allocatePixelFormat(width, height, of.PIXELS_GRAY)

print("------------------------------------------------")
print("Pixel color:", pixels:getColor(1,1))
print("Size:", pixels:size())
print("Bits per pixels", pixels:getBitsPerPixel())
print("Pixel channels", pixels:getNumChannels())
print("------------------------------------------------")

Returns:

------------------------------------------------
Pixel color:		0, 0, 0, 255 ?
Size:			389550.0
Bits per pixels		8.0
Pixel channels		1.0
------------------------------------------------

A few other C++ vectors might need to be wrapped (ofPolyline, ofPath)

This structure seems to be quite common in openFrameworks:
vector<ofPath>vector<ofPolyline> vector<ofVertex>

A use case with a similar structure that I was trying to use in Loaf is:
vector<ofPath> characters = font.getStringAsPoints(text)
Then:
vector <ofPolyline> outlines = characters[n].getOutline()
Then:
vector <ofVertex> vertices = outlines[n]

Now that vectors of vertices or points are now accessible, wrapping also the other containers would be a great addition to Loaf.

-- Define font
font = of.TrueTypeFont()
font:load("filename.ttf", 32)

-- Print each vertex of a character
characters = font:getStringAsPoints("Hello")
for i=0,characters:size() do
    outlines = characters[i]
    for n=0, outlines:size() do
        vertices = outlines[n]
        for m=0, vertices:size() do
            of.drawCircle(vertices[m],10)
        end
    end
end

Question: Confirmation of intent of GPL license

@danomatika
First of all, I am truly impressed with loaf, and thank you for developing such a great tool.

And I would like to contribute to the development of ofxLua and related additional add-ons, and therefore, I would like to reaffirm the intent of the license.

As a guess, I felt that the licensing structure is similar to Processing and processing.core, but there are some subtle differences, which resulted in significant differences.

If loaf had the ability to create stand-alone executables similar to the Processing IDE, the situation would be different. At this point, creating a program that links only to ofxLua requires manual creation, which is not much of a task for Lua scripts only, but if custom C++ add-ons are included, the licensing of the add-ons themselves and the licensing of the distribution software become somewhat tricky.

I myself of course would like to contribute to open software as much as possible, I would really appreciate it if I could confirm the intent of the license and the design policy.

processing and loaf license comparison

syphon would be nice

I figure with OSC and syphon, that's all you really need to intercommunicate.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.