Welcome to %s forums

BrainModular Users Forum

Login Register

programming a trigger

Create your own modules in C++
Post Reply
antwan
Member
Posts: 164
Contact:

Unread post by antwan » 28 Jan 2009, 21:36

Hi,

So I'm playing around with the C++ SDK. I'm very slowly building understanding of things but already getting somewhere...
Anyways, a question - I've posed this question before but for pascal-scripting:

What's the correct way to program a user module outlet to give a trigger (like for example a button-module gives), i.e. a rapid 1 and then 0, in the Process-function?

Cheers,

antwan

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 30 Jan 2009, 12:11

hi antwan,

sorry for the lag....
I've posed this question before but for pascal-scripting
do you refer to this thread ?

The process function is equivalent of the main proc in script, i believe, it's called each audio engine cycle by Usine.

so yes, it's the place to go, here a basic example :

Code: Select all

void Process (void* pModule) {
	TTriggerButtonTest* pTriggerButtonTest = ((TTriggerButtonTest*)pModule);
	
	if (pTriggerButtonTest->bWantTrigger) {
		if (pTriggerButtonTest->PTriggerOut->value == 1) {
			pTriggerButtonTest->PTriggerOut->value = 0;
			pTriggerButtonTest->bWantTrigger = FALSE;
		}
		else {
			pTriggerButtonTest->PTriggerOut->value = 1;
		}
	} 
}
where :
pTriggerButtonTest is your module class
bWantTrigger is the boolean flag used to manage the trigger, putted to TRUE by whatever you want
PTriggerOut is a button outlet

hope it help
Martin FLEURENT - Usine Developer - SDK maintainer

antwan
Member
Posts: 164
Contact:

Unread post by antwan » 31 Jan 2009, 16:15

Hi Martin,

Thank you, I got it to work!
I wasn't far off actually but non-the-less I was making some stupid mistakes. Now I got it.

I'll take the liberty to hijack my own thread for another question:
How to use the VstTimeInfo flags. I was trying to read about this, but didn't quite understand. For instance if I'm interested in for example kVstTransportPlaying (as its called in the VST SDK... not sure if that constant is available in Usine SDK)?

Let's say I want to "make" my own boolean flag from that piece of information, how do I go about it?

Thanks for all your help!

antwan

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 31 Jan 2009, 19:46

Hi antwan,
antwan wrote:How to use the VstTimeInfo flags. I was trying to read about this, but didn't quite understand. For instance if I'm interested in for example kVstTransportPlaying (as its called in the VST SDK... not sure if that constant is available in Usine SDK)?
The VstTimeInfoFlags enumeration isn't actually defined in the Usine SDK...

...but you can do it if needed by adding the following code before your YourModule class definition, in the YourModule.h file.

Directly from the VST SDK 2.4, in the plugin interface file aeffectx.h :

Code: Select all

//-------------------------------------------------------------------------------------------------------
/** Flags used in #VstTimeInfo. */
//-------------------------------------------------------------------------------------------------------
enum VstTimeInfoFlags
{
//-------------------------------------------------------------------------------------------------------
	kVstTransportChanged     = 1,		///< indicates that play, cycle or record state has changed
	kVstTransportPlaying     = 1 << 1,	///< set if Host sequencer is currently playing
	kVstTransportCycleActive = 1 << 2,	///< set if Host sequencer is in cycle mode
	kVstTransportRecording   = 1 << 3,	///< set if Host sequencer is in record mode
	kVstAutomationWriting    = 1 << 6,	///< set if automation write mode active &#40;record parameter changes&#41;
	kVstAutomationReading    = 1 << 7,	///< set if automation read mode active &#40;play parameter changes&#41;
	kVstNanosValid           = 1 << 8,	///< VstTimeInfo&#58;&#58;nanoSeconds valid
	kVstPpqPosValid          = 1 << 9,	///< VstTimeInfo&#58;&#58;ppqPos valid
	kVstTempoValid           = 1 << 10,	///< VstTimeInfo&#58;&#58;tempo valid
	kVstBarsValid            = 1 << 11,	///< VstTimeInfo&#58;&#58;barStartPos valid
	kVstCyclePosValid        = 1 << 12,	///< VstTimeInfo&#58;&#58;cycleStartPos and VstTimeInfo&#58;&#58;cycleEndPos valid
	kVstTimeSigValid         = 1 << 13,	///< VstTimeInfo&#58;&#58;timeSigNumerator and VstTimeInfo&#58;&#58;timeSigDenominator valid
	kVstSmpteValid           = 1 << 14,	///< VstTimeInfo&#58;&#58;smpteOffset and VstTimeInfo&#58;&#58;smpteFrameRate valid
	kVstClockValid           = 1 << 15	///< VstTimeInfo&#58;&#58;samplesToNextClock valid
//-------------------------------------------------------------------------------------------------------
&#125;;
The way to use it is not Usine or SDK related, but more C language knowledge ;)

To understand and using it, it's little more complex, i'll try to stay simple :)

kVstXXXXXXXX in the enum are bite mask, coded with the Bitwise Left Shift operator. I let you follow the link for precisions...
but finally, the kVstTransportPlaying variable contain '000000000000010' (so, one bite left shifted by on), ok ?

And to extract the info from the flags, you use the Bitewise AND operator (link for precisions)

so :

Code: Select all

if &#40;pTriggerButtonTest->pMasterInfo->pTimeInfo->flags & kVstTransportPlaying&#41; &#123;
   ...
&#125;
where pTriggerButtonTest->pMasterInfo->pTimeInfo->flags & kVstTransportPlaying is TRUE if the flags second bite from the right contain 1, that is.

Hope it's not too complex, welcome in C world :)

It's not finish, but i have a question.
Now, we have a test who return true when the host sequencer is playing, but what you want to do exactly, detecting when it begin to play ?
Martin FLEURENT - Usine Developer - SDK maintainer

antwan
Member
Posts: 164
Contact:

Unread post by antwan » 31 Jan 2009, 20:53

Hi!

Thanks once again!
Actually I hacked it meanwhile after reading the definition of the flags enum somewhere online. So without understanding what I was doing I got it right by typing
if (pMyUserModule->pMasterInfo->pTimeInfo->flags & 1 << 1) {

So I was just coming back to change my question to: What did I just do? What does this mean?

So thanks for already answering that and thanks for the clarification and the links, I will read through it. I have read about shift operators and such before, but I didn't understand it. With the help of this case study I'm sure I'll understand it better.
I hope to have my first simple user module complete tomorrow so you should get your answer about what it's for tomorrow - if all goes well :)

thanks again!

antwan

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 31 Jan 2009, 21:13

cool, cant wait to see that
Martin FLEURENT - Usine Developer - SDK maintainer

antwan
Member
Posts: 164
Contact:

Unread post by antwan » 01 Feb 2009, 12:22

Hi,

I've got (at least) one remaining problem with all this: I can't seem to be getting any reading from BarStartPos or CycleStartPos. Any idea why?

Cheers,

antwan

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 01 Feb 2009, 18:22

hi,

cant help on this, i even don't know what they mean, what kind of infos should they display ?
Martin FLEURENT - Usine Developer - SDK maintainer

antwan
Member
Posts: 164
Contact:

Unread post by antwan » 01 Feb 2009, 20:44

They should contain the PpqPos of the start (beat 1) of the current bar or cycle. This is probably a question for Olivier then ;)

Cheers,

antwan

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests