wait for a port connection v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 30 Sep 2020 21:37:01 +0200
branchv_0
changeset 5 6be3464ccb2b
parent 4 65dfbf0494a3
child 6 4174fc0c2e7c
wait for a port connection
src/JackHandler.h
--- a/src/JackHandler.h	Wed Sep 30 20:54:39 2020 +0200
+++ b/src/JackHandler.h	Wed Sep 30 21:37:01 2020 +0200
@@ -96,6 +96,10 @@
 
 		int jackError = jack_activate(jackClient);
 		if (jackError) throw JackException(L"Could not activate client.");
+
+		// Wait for a port connection, because it does not make much sense to send MIDI events nowhere:
+		// TODO: configurable waiting?
+		while (jack_port_connected(jackPort) == 0) usleep(10000);
 	}
 
 	void startRelation(const relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override {
@@ -150,6 +154,7 @@
 				MidiMessage m;
 				jack_ringbuffer_read(ringBuffer, (char*) &m, sizeof (MidiMessage));
 				// TODO: send events from the ring buffer to JACK + correct timing
+				// FIXME: do not block here in the while loop; check frames
 				std::cout << "will process MidiMessage: " << &m << "" << std::endl; // TODO: remove debug message
 			}
 			pthread_cond_wait(&dataReady, &messageThreadLock);