Skip to content

Commit

Permalink
Initial work for time-pos support (via dummy jack-client)
Browse files Browse the repository at this point in the history
  • Loading branch information
falkTX committed Jun 9, 2012
1 parent 01fdafb commit 5f98481
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 9 deletions.
22 changes: 17 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ WINECXX ?= wineg++ -m32

PREFIX ?= /usr/local

BIN_DIR = $(PREFIX)/bin
DSSI_DIR = $(PREFIX)/lib/dssi
LADSPA_DIR = $(PREFIX)/lib/ladspa
BIN_DIR = $(DESTDIR)$(PREFIX)/bin
DSSI_DIR = $(DESTDIR)$(PREFIX)/lib/dssi
LADSPA_DIR = $(DESTDIR)$(PREFIX)/lib/ladspa

BUILD_FLAGS = -O2 -ffast-math -fvisibility=hidden -fPIC -mtune=generic -msse -Wall -Ivestige $(CXX_FLAGS)
BUILD_FLAGS += $(shell pkg-config --cflags alsa liblo)
LINK_FLAGS = $(LDFLAGS)

LINK_PLUGIN = -shared $(shell pkg-config --libs alsa) $(LINK_FLAGS)
LINK_PLUGIN = -shared $(shell pkg-config --libs alsa jack) $(LINK_FLAGS)
LINK_HOST = $(shell pkg-config --libs alsa jack) $(LINK_FLAGS)
LINK_GUI = $(shell pkg-config --libs liblo) $(LINK_FLAGS)
LINK_WINE = -m32 -L/usr/lib32/wine -L/usr/lib/i386-linux-gnu/wine -lpthread $(LINK_FLAGS)
Expand All @@ -38,7 +38,7 @@ dssi-vst-scanner.exe: dssi-vst-scanner.wine.o libremoteplugin.wine.a
$(WINECXX) $^ $(LINK_WINE) -o $@

dssi-vst-server.exe: dssi-vst-server.wine.o libremoteplugin.wine.a
$(WINECXX) $^ $(LINK_WINE) -o $@
$(WINECXX) $^ $(LINK_WINE) -ljack -o $@

vsthost: remotevstclient.o vsthost.o libremoteplugin.unix.a
$(CXX) $^ $(LINK_HOST) -o $@
Expand Down Expand Up @@ -92,3 +92,15 @@ libremoteplugin.wine.a: paths.wine.o remotepluginclient.wine.o remotepluginserve

clean:
rm -f *.a *.o *.exe *.so $(TARGETS)

install:
install -d $(BIN_DIR)
install -d $(DSSI_DIR)
install -d $(DSSI_DIR)/dssi-vst
install -d $(LADSPA_DIR)
install -m 755 vsthost $(BIN_DIR)
install -m 755 dssi-vst.so $(DSSI_DIR)
install -m 755 dssi-vst_gui $(DSSI_DIR)/dssi-vst
install -m 755 dssi-vst-scanner.exe dssi-vst-scanner.exe.so $(DSSI_DIR)/dssi-vst
install -m 755 dssi-vst-server.exe dssi-vst-server.exe.so $(DSSI_DIR)/dssi-vst
install -m 755 dssi-vst.so $(LADSPA_DIR)
67 changes: 63 additions & 4 deletions dssi-vst-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#include <jack/jack.h>

#define VST_FORCE_DEPRECATED 0
#include "aeffectx.h"

Expand Down Expand Up @@ -66,9 +68,13 @@ static int sampleRate = 0;
static bool guiVisible = false;
static bool needIdle = false;

static RemotePluginDebugLevel debugLevel = RemotePluginDebugSetup;
static RemotePluginDebugLevel debugLevel = RemotePluginDebugNone;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

static jack_client_t* jack_client = 0;
static int jack_process_callback(jack_nframes_t, void*)
{ return 0; }

using namespace std;

class RemoteVSTServer : public RemotePluginServer
Expand Down Expand Up @@ -691,6 +697,7 @@ RemoteVSTServer::terminateGUIProcess()
}

#if 1 // vestige header
#define kVstTransportChanged 1
#define kVstVersion 2400
struct VstTimeInfo_R {
double samplePos, sampleRate, nanoSeconds, ppqPos, tempo, barStartPos, cycleStartPos, cycleEndPos;
Expand Down Expand Up @@ -776,9 +783,46 @@ hostCallback(AEffect *plugin, long opcode, long index,
// if (debugLevel > 1)
// cerr << "dssi-vst-server[2]: audioMasterGetTime requested" << endl;
memset(&timeInfo, 0, sizeof(VstTimeInfo_R));
timeInfo.samplePos = currentSamplePosition;
timeInfo.sampleRate = sampleRate;
timeInfo.flags = 0; // don't mark anything valid except default samplePos/Rate
timeInfo.sampleRate = sampleRate;
timeInfo.samplePos = currentSamplePosition;

if (jack_client)
{
static jack_position_t jack_pos;
static jack_transport_state_t jack_state;

jack_state = jack_transport_query(jack_client, &jack_pos);

timeInfo.flags |= kVstTransportChanged;

if (jack_state != JackTransportStopped)
timeInfo.flags |= kVstTransportPlaying;

if (jack_pos.unique_1 == jack_pos.unique_2)
{
timeInfo.sampleRate = jack_pos.frame_rate;
timeInfo.samplePos = jack_pos.frame;

if (jack_pos.valid & JackPositionBBT)
{
// Tempo
timeInfo.tempo = jack_pos.beats_per_minute;
timeInfo.flags |= kVstTempoValid;

// Time Signature
timeInfo.timeSigNumerator = jack_pos.beats_per_bar;
timeInfo.timeSigDenominator = jack_pos.beat_type;
timeInfo.flags |= kVstTimeSigValid;

// Position
double dPos = timeInfo.samplePos / timeInfo.sampleRate;
timeInfo.barStartPos = 0;
timeInfo.nanoSeconds = dPos * 1000.0;
timeInfo.ppqPos = dPos * timeInfo.tempo / 60.0;
timeInfo.flags |= kVstBarsValid|kVstNanosValid|kVstPpqPosValid;
}
}
}
rv = (intptr_t)&timeInfo;
break;

Expand Down Expand Up @@ -1434,6 +1478,15 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR cmdline, int cmdshow)
return 1;
}

// create dummy jack client for transport info
jack_client = jack_client_open("dssi-vst", JackNoStartServer, 0);

if (jack_client)
{
jack_set_process_callback(jack_client, jack_process_callback, 0);
jack_activate(jack_client);
}

HWND window;
if ((window = CreateWindowExA
(0, "dssi-vst", "dummy",
Expand Down Expand Up @@ -1501,6 +1554,12 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR cmdline, int cmdshow)
cerr << "dssi-vst-server[1]: cleaning up" << endl;
}

if (jack_client)
{
jack_deactivate(jack_client);
jack_client_close(jack_client);
}

CloseHandle(audioThreadHandle);
if (debugLevel > 0) {
cerr << "dssi-vst-server[1]: closed audio thread" << endl;
Expand Down

0 comments on commit 5f98481

Please sign in to comment.