Connecting third-party GitHub library?

To create a midi-player I use an example found on the Internet. When building, I get a bunch of error alerts like “is not a member of” and “has no member” because the third-party code employs a lib from GitHub. I’m a newbie to Juce. So how should I correctly connect a third-party library?

Just in case a code I use is below:

void playMidiFile::run() {
   
    MidiMessage message_midi(0x80, 0, 0, 0);
    Message* listenerMsg = new Message();
    int numEvents = MidiMsgSequence.getNumEvents();
    int currentPosition = 0;
    double TPQN = static_cast<double>(mFile.getTimeFormat());
    double nextEventTime = 0.;
    double msPerTick = 500. / TPQN; // default 120 BPM
    double prevTimestamp = 0.;
    void* pointerParameter;
    setPosition(0);
    sendActionMessage(L"Play");

    while (( !threadShouldExit() ) && ( currentPosition < numEvents )) {

        if (isPaused())
                     continue;
       
        message_midi = MidiMsgSequence.getEventPointer(currentPosition)->message;

        if (mFilter) 
               mFilter->filterMessage(message_midi);
        nextEventTime = msPerTick * (message_midi.getTimeStamp() - prevTimestamp);

        Time::waitForMillisecondCounter(Time::getMillisecondCounter() + nextEventTime);
     if (MsgListener->isValidMessageListener())        {
                                 listenerMsg->pointerParameter = (void*) &message_midi;
                                 MsgListener->postMessage(listenerMsg);
                                                                       }
        
        if (message_midi.isTempoMetaEvent()) {
            msPerTick = message_midi.getTempoSecondsPerQuarterNote() * 1000. / TPQN;
        } else 
             if (!message_midi.isMetaEvent()) {
                 outDevice->sendMessageNow(message_midi);
        }

        if (static_cast<int>(prevTimestamp) % static_cast<int>(TPQN) == 0)
                                                                    sendChangeMessage();

        prevTimestamp = message_midi.getTimeStamp();
        setPosition(++currentPosition);

    }
    delete listenerMsg;
    reset();
    sendActionMessage(L"Stop");
}

Please re-format your post so that your code snippet becomes more readable. Put a line of ``` above and below your code and everything in between will become nicely readable.

Then without reformatting, I spot the line: double TPQN = static_cast(mFile.getTimeFormat());. That won’t compile – you need to specify to what type you want to cast your argument. E.g. like

double d = 2.0;
int i = static_cast<int> (d); //--> this casts the double above into an int
float f = static_cast<float> (d); // --> this casts the double above into a float

Not sure if this was a copy&paste error (we all do them) or if you should start with some c++ basics before trying to link to 3rd party code?

1 Like

Thanks for giving the heads-up. But I’ll fix it later being in experienced C++ coder but in Borland/Embarcadero IDE.

My topic is about finding out a proper way of connecting third-party libraries in Juce, for which I’m newbie. Thanks!

Thank you for reformatting – looks a lot more readable now :slight_smile:

By scanning over the code snippets you supplied I don’t spot any obvious call to none-juce functionality from a third party lib :thinking:. Could you give a pointer on which exact library do you need to add to your project? There is no one-fits-all answer on how to handle libraries correctly, it depends a lot of how the library is designed.

These are compiler alerts:

Error C2039 pointerParameter: is not a member of “juce::Message”
Error C2039 isValidMessageListener: is not a member of “juce::MessageListener”
E0135 class “juce::MessageListener” has no member “isValidMessageListener”
E0135 class “juce::Message” has no member “pointerParameter”

TBH if that project has no readme file, where it explains how it is intended to be used, I wouldn’t waste my time with it.
It would also help the community to help, if you told which project you are talking about (link?)

The term library is quite generic, and the method how to add it to your project vary, like PluginPenguin pointed out. There are:

  • static libraries
  • dynamic libraries
  • header only libraries
  • some refer to 3rd-party juce modules as libraries

Again, telling which library you try to add would help people helping…

juce::MessageListener::isValidMessageListener was removed in commit e905f52 (around JUCE 2.0.0), in March 2012. If that third-party code was not updated in 8 years, you won’t have a good time using it.

1 Like

What is the 3rd party library you are attempting to use?

It’s a secret, many people tried to steal it from the OP :wink:

Are you maybe not trying to use a 3rd party library but trying to compile some very old JUCE code (pre 2012) found somewhere on GitHub?

This one: https://github.com/SonicPotions/editor/tree/master/juce/src/events

If it’s outdated what can it be replaced with?