send correct number of messages to the ring buffer v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri, 02 Oct 2020 00:18:34 +0200
branchv_0
changeset 8 27579c5cdc51
parent 7 b2fc99295546
child 9 14cf28d7681c
send correct number of messages to the ring buffer
src/JackHandler.h
--- a/src/JackHandler.h	Thu Oct 01 19:35:49 2020 +0200
+++ b/src/JackHandler.h	Fri Oct 02 00:18:34 2020 +0200
@@ -97,8 +97,10 @@
 		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?
+		// TODO: configurable waiting (number of connections)
 		while (jack_port_connected(jackPort) == 0) usleep(10000);
+
+		// TODO: configurable auto-connection to another client/port
 	}
 
 	void startRelation(const relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override {
@@ -111,21 +113,21 @@
 		// TODO: append to current message + if this is last attribute, put whole message to the ring buffer
 		// TODO: if (continueProcessing) {} ?
 
-		if (currentAttributeIndex < currentAttributeCount) {
-			// memcpy(currentMidiMessage.buffer, ….buffer, ….size);
-			// currentMidiMessage.size = …;
-			// currentMidiMessage.time = …;
+		// memcpy(currentMidiMessage.buffer, ….buffer, ….size);
+		// currentMidiMessage.size = …;
+		// currentMidiMessage.time = …;
 
-			// TODO: correct timing?
-			// TODO: real data
-			currentMidiMessage.time = 0;
-			currentMidiMessage.size = 3;
-			currentMidiMessage.buffer[0] = 0x80;
-			currentMidiMessage.buffer[1] = 0x34;
-			currentMidiMessage.buffer[2] = 0x40;
+		// TODO: correct timing?
+		// TODO: real data
+		currentMidiMessage.time = 0;
+		currentMidiMessage.size = 3;
+		currentMidiMessage.buffer[0] = 0x90;
+		currentMidiMessage.buffer[1] = 0x24;
+		currentMidiMessage.buffer[2] = 0x40;
 
-			currentAttributeIndex++;
-		} else {
+		currentAttributeIndex++;
+
+		if (currentAttributeIndex == currentAttributeCount) {
 			if (jack_ringbuffer_write_space(ringBuffer) >= sizeof (MidiMessage)) {
 				jack_ringbuffer_write(ringBuffer, (const char *) &currentMidiMessage, sizeof (MidiMessage));
 				std::cout << "jack_ringbuffer_write" << std::endl;
@@ -146,6 +148,7 @@
 		while (continueProcessing && jack_ringbuffer_read_space(ringBuffer)) usleep(1000);
 		usleep(1000000);
 		// TODO: better waiting (ringBuffer might be empty, but events have not been sent to JACK yet)
+		// TODO: optionally mute all; probably enabled by default
 	}
 
 	int dequeueMessages(jack_nframes_t frames) {