ofSleepMillis()

Hi, I have a small question, I have tried to use ofSleepMillis() to extent the length of incoming midi notes, but this actually makes the whole program sleep for the time set. What I want to do is choose to extent an incoming midi note by delaying the note off signal. Alternately I could delay its reaction to the parameters in my program but again ofSleepMillis() will not do the job.

Is there a way to have a very specific time delay that does not effect the running program, only the event(s) in question. I want to be able to specify the time accurate to at least within 50 milliseconds.

Cheers

Fred

you could implement a timer function using ofGetElapsedTimeMillis().
start with note on,
if currenttime>starttime+desiredlengthofnote -> note off.

can you post some code? the way to go will be different if you’re for example using prerecorded sounds and triggering them using soundplayers or doing sound synthesis.

Ok, I am using midi notes to trigger DMX only. I have posted 1 portion of my midi note to DMX below. I have a GUI option to tun on and off the delay, and to select the amount the DMX signal is delayed for. This portion of code is what I tried using the ofsleepmillis function, but it does not do what I want. I have 8 channels at the moment, so there are 8 versions of this. I am a little embarrassed about my code, I am sure it is not a good way to do it but I am a beginner so I have a lot to learn. I am trying to make a more reliable tool for my performances-like this http://heavymetalworkorchestra.com/shows.html.

Thanks again for your help.

  
	if (args.byteOne==chFive.triggerNote&&args.status==144) {  
		cout << "Note 5 on " << args.port << ", channel: " << args.channel << ", status: " << args.status << ", byteOne: " << args.byteOne << ", byteTwo: " << args.byteTwo << ", timestamp: " << args.timestamp << "]" << endl;  
		if (ch5GuiMultiplierEnable==true){  
			dmxData[chFive.dmxChannel]=args.byteTwo/127*255*chFive.multiplier;  
			dmxInterface.sendDmxPacket(dmxData);  
			//dmxInterface.sendDataDirectly(dmxData);  
		}  
		else {  
			dmxData[chFive.dmxChannel]=args.byteTwo/127*255;  
			dmxInterface.sendDmxPacket(dmxData);  
		}  
	}  
	  
	if (args.byteOne==chFive.triggerNote&&args.status==128) {  
		if (chFive.timeExtend=true) {  
			ofSleepMillis(chFive.timeExtendAmount);  
		}  
		cout << "Note 5 off " << args.port << ", channel: " << args.channel << ", status: " << args.status << ", byteOne: " << args.byteOne << ", byteTwo: " << args.byteTwo << ", timestamp: " << args.timestamp << "]" << endl;  
			  
		dmxData[chFive.dmxChannel]=0;  
		dmxInterface.sendDmxPacket(dmxData);  
		//dmxInterface.sendDataDirectly(dmxData);  
	}  

there’s a problem with this:

  
if (chFive.timeExtend=true) {  
         ofSleepMillis(chFive.timeExtendAmount);  
      }  

since:

  
chFive.timeExtend=true  

should be

  
  
chFive.timeExtend==true  

you could use a thread with ofxThread so doing ofSleepMillis will sleep the thread and not the whole application or as bilderbuchi says, check the passed time since the last update and if it’s more than the note length then turn it off.

Thanks for the tip, I will try using thread and see how it goes.