Skip to content

Instantly share code, notes, and snippets.

View gaspard's full-sized avatar

Gaspard Bucher gaspard

View GitHub Profile
{-
Rendering this:
+------+
| main |
+------+
|
+-------------+
| a. Anaglyph |
@gaspard
gaspard / gist:6448474
Created September 5, 2013 10:30
Simple VST plugin to test midi sync.
#ifndef MIDI_RANDOM_INCLUDE_PLUGIN_H_
#define MIDI_RANDOM_INCLUDE_PLUGIN_H_
#include "vst2.x/audioeffectx.h"
#include <cstdlib> // rand
// just one program
#define NUM_PROGRAMS 1
// no other parameter
@gaspard
gaspard / gist:6415937
Last active July 13, 2020 19:33
VST plugin: sample accurate midi out.
// This is part of a midi generating plugin made with Juce library.
//
// The goal of this thing is simply to generate random midi notes that are on-time
// with sample accuracy.
void MidiRandomAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
// Clear all
for (int i = 0; i < getNumOutputChannels(); ++i)
{
@gaspard
gaspard / main.cpp
Created March 25, 2012 11:15
Minimal main program for bug 24945
#include <dlfcn.h>
#include <cstdio>
#include <cstring> // strerror
#include <errno.h> // errno
typedef void(*test_func)(bool);
int main() {
printf("Qt BUG related to dlclose\n=========================\n1. Program starting.\n");
printf("2. Loading dynamic library 'mod.so' linked to Qt.\n");
@gaspard
gaspard / mod.cpp
Created March 25, 2012 11:15
Simple Qt module producing bug 24945
#include <QtGui/QApplication>
#include <QtCore/QTimer>
#include <qglobal.h>
#include <cstdio>
static int app_argc = 0;
static char *app_argv[] = {};
static void something() {
@gaspard
gaspard / gist:1636042
Created January 18, 2012 21:54
Simple Box2D demo with Lubyk
require 'lubyk'
-- Box2D bindings are not yet in published but code will look the same
-- (18.1.2012)
local function makeBody(x, y, r, hue)
-- Define the dynamic body. We set its position and call the body factory.
local bodyDef = b2.BodyDef()
bodyDef.type = b2.dynamicBody
bodyDef.position:Set(x, y)
@gaspard
gaspard / gist:1614891
Created January 15, 2012 07:42
dub optimizations
// =========================================================== Return value optimization
/** Vect Vect::operator+(const Vect &v)
* test/fixtures/pointers/Vect.h:55
*/
static int Vect_operator_add(lua_State *L) {
try {
Vect *self = *((Vect**)dub_checksdata(L, 1, "Vect"));
Vect *v = *((Vect**)dub_checksdata(L, 2, "Vect"));
dub_pushudata(L, new Vect(self->operator+(*v)), "Vect");
@gaspard
gaspard / simple_jit.lua
Created July 17, 2011 09:05
Testing Luajit bindings to C++
-- luajit simple_jit.lua
ffi = require 'ffi'
simple = ffi.load('simple')
ffi.cdef[[
typedef struct Simple Simple;
Simple *Simple_Simple(int);
void Simple__gc(Simple *);
@gaspard
gaspard / gist:1087380
Created July 17, 2011 09:02
Simple C++ class with C interface for Luajit ffi bindings
// g++ simple.cpp -shared -o libsimple.dylib
#include <stdio.h>
class Simple {
int id_;
public:
Simple(int id);
~Simple();
@gaspard
gaspard / gist:1054915
Created June 29, 2011 20:47
wrapping C++ classes with Lua
-- ============ Create new class
SpecialEdit = {}
setmetatable(SpecialEdit, mimas.LineEdit_mt)
-- calling SpecialEdit() should do the following things
-- 1. create userdata
-- 2. set new table as uservale ---> self
-- 3. create new lua thread and install "self" on the stack
-- 4. set access to userdata from self ---> self.super = userdata
-- 5. set "SpecialEdit" as metatable for "self" ---> setmetatable(self, SpecialEdit)