From 5f984818e51ebf377e721a0d4b649983cb628d5e Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 9 Jun 2012 06:48:23 +0100 Subject: [PATCH] Initial work for time-pos support (via dummy jack-client) --- Makefile | 22 +++++++++++---- dssi-vst-server.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 80 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index d8c9536..debbc1a 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -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 $@ @@ -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) diff --git a/dssi-vst-server.cpp b/dssi-vst-server.cpp index 2631150..d73b4e2 100644 --- a/dssi-vst-server.cpp +++ b/dssi-vst-server.cpp @@ -26,6 +26,8 @@ #define WIN32_LEAN_AND_MEAN #include +#include + #define VST_FORCE_DEPRECATED 0 #include "aeffectx.h" @@ -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 @@ -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; @@ -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; @@ -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", @@ -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;