diff --git a/macosx/Jackdmp.xcodeproj/project.pbxproj b/macosx/Jackdmp.xcodeproj/project.pbxproj index bcad2215..05932d90 100644 --- a/macosx/Jackdmp.xcodeproj/project.pbxproj +++ b/macosx/Jackdmp.xcodeproj/project.pbxproj @@ -274,7 +274,6 @@ 4B35C5490D4731D1000DE7AE /* connect.c in Sources */ = {isa = PBXBuildFile; fileRef = 4B60CE480AAABA31004956AA /* connect.c */; }; 4B35C5570D4731D2000DE7AE /* freewheel.c in Sources */ = {isa = PBXBuildFile; fileRef = 4BF8D1710834EE0F00C94B91 /* freewheel.c */; }; 4B35C5630D4731D2000DE7AE /* jdelay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFA99A90AAAF40C009E916C /* jdelay.cpp */; }; - 4B35C56F0D4731D2000DE7AE /* external_metro.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BF8D1750834EE3600C94B91 /* external_metro.cpp */; }; 4B35C57D0D4731D2000DE7AE /* testAtomic.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BF8D23E0834F1C300C94B91 /* testAtomic.cpp */; }; 4B35C58D0D4731D2000DE7AE /* testSem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BF8D2470834F20600C94B91 /* testSem.cpp */; }; 4B35C59F0D4731D2000DE7AE /* zombie.c in Sources */ = {isa = PBXBuildFile; fileRef = 4BF8D1670834EDD900C94B91 /* zombie.c */; }; @@ -449,7 +448,6 @@ 4B699CB4097D421600A18468 /* metro.c in Sources */ = {isa = PBXBuildFile; fileRef = 4BF8D16B0834EDF000C94B91 /* metro.c */; }; 4B699CC4097D421600A18468 /* lsp.c in Sources */ = {isa = PBXBuildFile; fileRef = 4BF8D1690834EDE600C94B91 /* lsp.c */; }; 4B699CF6097D421600A18468 /* freewheel.c in Sources */ = {isa = PBXBuildFile; fileRef = 4BF8D1710834EE0F00C94B91 /* freewheel.c */; }; - 4B699D06097D421600A18468 /* external_metro.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BF8D1750834EE3600C94B91 /* external_metro.cpp */; }; 4B699D18097D421600A18468 /* testAtomic.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BF8D23E0834F1C300C94B91 /* testAtomic.cpp */; }; 4B699D2C097D421600A18468 /* testSem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BF8D2470834F20600C94B91 /* testSem.cpp */; }; 4B699D42097D421600A18468 /* zombie.c in Sources */ = {isa = PBXBuildFile; fileRef = 4BF8D1670834EDD900C94B91 /* zombie.c */; }; @@ -1351,7 +1349,6 @@ 4BF8D1690834EDE600C94B91 /* lsp.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lsp.c; path = "..//example-clients/lsp.c"; sourceTree = SOURCE_ROOT; }; 4BF8D16B0834EDF000C94B91 /* metro.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = metro.c; path = "../example-clients/metro.c"; sourceTree = SOURCE_ROOT; }; 4BF8D1710834EE0F00C94B91 /* freewheel.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = freewheel.c; path = "../example-clients/freewheel.c"; sourceTree = SOURCE_ROOT; }; - 4BF8D1750834EE3600C94B91 /* external_metro.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = external_metro.cpp; path = "../example-clients/external_metro.cpp"; sourceTree = SOURCE_ROOT; }; 4BF8D1770834EE4800C94B91 /* JackError.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = JackError.h; path = ../common/JackError.h; sourceTree = SOURCE_ROOT; }; 4BF8D1830834EE5800C94B91 /* JackTime.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = JackTime.h; path = ../common/JackTime.h; sourceTree = SOURCE_ROOT; }; 4BF8D1870834EE7900C94B91 /* JackShmMem.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = JackShmMem.h; path = ../common/JackShmMem.h; sourceTree = SOURCE_ROOT; }; @@ -2111,7 +2108,6 @@ 4BF8D1690834EDE600C94B91 /* lsp.c */, 4BF8D16B0834EDF000C94B91 /* metro.c */, 4BF8D1710834EE0F00C94B91 /* freewheel.c */, - 4BF8D1750834EE3600C94B91 /* external_metro.cpp */, 4B363F3D0DEB0C31001F72D9 /* showtime.c */, ); name = "Simple clients"; @@ -5454,7 +5450,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 4B35C56F0D4731D2000DE7AE /* external_metro.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -5809,7 +5804,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 4B699D06097D421600A18468 /* external_metro.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/example-clients/external_metro.cpp b/tests/external_metro.cpp similarity index 77% rename from example-clients/external_metro.cpp rename to tests/external_metro.cpp index fab774cd..640bbb31 100644 --- a/example-clients/external_metro.cpp +++ b/tests/external_metro.cpp @@ -17,12 +17,13 @@ */ #include "external_metro.h" +#include typedef jack_default_audio_sample_t sample_t; const double PI = 3.14; -static int process_audio (jack_nframes_t nframes, void* arg) +int ExternalMetro::process_audio (jack_nframes_t nframes, void* arg) { ExternalMetro* metro = (ExternalMetro*)arg; sample_t *buffer = (sample_t *) jack_port_get_buffer (metro->output_port, nframes); @@ -41,6 +42,11 @@ static int process_audio (jack_nframes_t nframes, void* arg) return 0; } +void ExternalMetro::shutdown (void* arg) +{ + printf("shutdown called..\n"); +} + ExternalMetro::ExternalMetro(int freq, double max_amp, int dur_arg, int bpm, char* client_name) { sample_t scale; @@ -48,6 +54,8 @@ ExternalMetro::ExternalMetro(int freq, double max_amp, int dur_arg, int bpm, cha double *amp; int attack_percent = 1, decay_percent = 10; char *bpm_string = "bpm"; + jack_options_t options = JackNullOption; + jack_status_t status; offset = 0; @@ -56,12 +64,13 @@ ExternalMetro::ExternalMetro(int freq, double max_amp, int dur_arg, int bpm, cha client_name = (char *) malloc (9 * sizeof (char)); strcpy (client_name, "metro"); } - if ((client = jack_client_new (client_name)) == 0) { + if ((client = jack_client_open (client_name, options, &status)) == 0) { fprintf (stderr, "jack server not running?\n"); - return ; + return; } jack_set_process_callback (client, process_audio, this); + jack_on_shutdown (client, shutdown, this); output_port = jack_port_register (client, bpm_string, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); input_port = jack_port_register (client, "metro_in", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); @@ -127,14 +136,16 @@ int main (int argc, char *argv[]) ExternalMetro* client3 = NULL; ExternalMetro* client4 = NULL; ExternalMetro* client5 = NULL; - + + printf("Testing multiple Jack clients in one process: open 5 metro clients...\n"); client1 = new ExternalMetro(1200, 0.4, 20, 80, "t1"); client2 = new ExternalMetro(600, 0.4, 20, 150, "t2"); client3 = new ExternalMetro(1000, 0.4, 20, 110, "t3"); client4 = new ExternalMetro(400, 0.4, 20, 200, "t4"); client5 = new ExternalMetro(1500, 0.4, 20, 150, "t5"); - while ((getchar() != 'q')) { + printf("Type 'c' to close alls client and go to next test...\n"); + while ((getchar() != 'c')) { sleep(1); }; @@ -143,4 +154,32 @@ int main (int argc, char *argv[]) delete client3; delete client4; delete client5; + + printf("Testing quiting the server while a client is running...\n"); + client1 = new ExternalMetro(1200, 0.4, 20, 80, "t1"); + + printf("Now quit the server, shutdown callback should be called...\n"); + printf("Type 'c' move on...\n"); + while ((getchar() != 'c')) { + sleep(1); + }; + + printf("Closing client...\n"); + delete client1; + + printf("Now start the server again...\n"); + printf("Type 'c' move on...\n"); + while ((getchar() != 'c')) { + sleep(1); + }; + + printf("Opening a new client....\n"); + client1 = new ExternalMetro(1200, 0.4, 20, 80, "t1"); + + printf("Type 'q' to quit...\n"); + while ((getchar() != 'q')) { + sleep(1); + }; + delete client1; + return 0; } diff --git a/example-clients/external_metro.h b/tests/external_metro.h similarity index 93% rename from example-clients/external_metro.h rename to tests/external_metro.h index dad2e878..d7d4b800 100644 --- a/example-clients/external_metro.h +++ b/tests/external_metro.h @@ -58,6 +58,8 @@ extern "C" ExternalMetro(int freq, double max_amp, int dur_arg, int bpm, char* client_name); virtual ~ExternalMetro(); + static int process_audio (jack_nframes_t nframes, void* arg); + static void shutdown (void* arg); }; #ifdef __cplusplus diff --git a/tests/wscript b/tests/wscript index 4e008caf..70c860b1 100644 --- a/tests/wscript +++ b/tests/wscript @@ -9,6 +9,7 @@ test_programs = { 'jack_test': ['jack_test.cpp'], 'jack_cpu': ['jack_cpu.c'], 'jdelay': ['jdelay.cpp'], + 'multiple_metro' : ['external_metro.cpp'], } def build(bld):