Katana MKII - Mac USB Communication (C++)

Started by StevenMartin, May 08, 2021, 02:08:27 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

StevenMartin

Does anyone know where I would need to start digging to find out how to communicate with the Katana MKII from a Mac using C++?

In this sense I'm not talking about from an Arduino or Teensy but from a mac application I am working on. I was hoping to port the legendary MS3 library across to handle the grunt of the communication to the Katana but as a relative noob to C++ I don't know what to be searching for really in terms of finding/creating a usb connection to the Katana and then reading/writing to the usb port (hopefully via the MS3 library!)

Any tips or pointers in the right direction would be appreciated!

admin


gumtown

Katana MK2 FxFloorBoard editor C++ source code
https://sourceforge.net/projects/fxfloorboard/files/KatanaFxFloorBoard/Katana%20FxFloorboard%20for%20MK2%20Desktop/

The *.h & *.cpp files of interest just for midi I/O are RtMidi and midiIO
Free "GR-55 FloorBoard" editor software from https://sourceforge.net/projects/grfloorboard/

StevenMartin

#3
RtMidi looks like it might well be the answer!

I've added the RtMidi.h and RtMidi.cpp into my project folder and included them, then when I run the midiprobe.cpp code from https://github.com/thestk/rtmidi :


// midiprobe.cpp
//
// Simple program to check MIDI inputs and outputs.
//
// by Gary Scavone, 2003-2012.

#include <iostream>
#include <cstdlib>
#include <map>
#include "RtMidi.h"

int main()
{
  // Create an api map.
  std::map<int, std::string> apiMap;
  apiMap[RtMidi::MACOSX_CORE] = "OS-X CoreMIDI";
  apiMap[RtMidi::WINDOWS_MM] = "Windows MultiMedia";
  apiMap[RtMidi::UNIX_JACK] = "Jack Client";
  apiMap[RtMidi::LINUX_ALSA] = "Linux ALSA";
  apiMap[RtMidi::RTMIDI_DUMMY] = "RtMidi Dummy";

  std::vector< RtMidi::Api > apis;
  RtMidi :: getCompiledApi( apis );

  std::cout << "\nCompiled APIs:\n";
  for ( unsigned int i=0; i<apis.size(); i++ )
    std::cout << "  " << apiMap[ apis[i] ] << std::endl;
  std::cout << std::endl;

  for ( unsigned int i=0; i<apis.size(); i++ ){
    std::cout << "Probing with API " << apiMap[ apis[i] ] << std::endl;

    RtMidiIn  *midiin = 0;
    RtMidiOut *midiout = 0;

    try {

      // RtMidiIn constructor ... exception possible
      midiin = new RtMidiIn(apis[i]);

      std::cout << "\nCurrent input API: " << apiMap[ midiin->getCurrentApi() ] << std::endl;

      // Check inputs.
      unsigned int nPorts = midiin->getPortCount();
      std::cout << "\nThere are " << nPorts << " MIDI input sources available.\n";

      for ( unsigned i=0; i<nPorts; i++ ) {
        std::string portName = midiin->getPortName(i);
        std::cout << "  Input Port #" << i << ": " << portName << '\n';
      }

      // RtMidiOut constructor ... exception possible
      midiout = new RtMidiOut(apis[i]);

      std::cout << "\nCurrent output API: " << apiMap[ midiout->getCurrentApi() ] << std::endl;

      // Check outputs.
      nPorts = midiout->getPortCount();
      std::cout << "\nThere are " << nPorts << " MIDI output ports available.\n";

      for ( unsigned i=0; i<nPorts; i++ ) {
        std::string portName = midiout->getPortName(i);
        std::cout << "  Output Port #" << i << ": " << portName << std::endl;
      }
      std::cout << std::endl;

    } catch ( RtMidiError &error ) {
      error.printMessage();
    }

    delete midiin;
    delete midiout;
  }

  return 0;
}


the output I get (with the Katana plugged into the mac and powered on) is:


MidiInDummy: This class provides no functionality.


There are 0 MIDI input sources available.

MidiOutDummy: This class provides no functionality.


There are 0 MIDI output ports available.


I'm guessing I should be expecting to see CoreMidi Api instead of the DummyApi, and 1 input and 1 output as the Katana, no? Boss Tone Studio seems to recognise the Katana.

I've been trying to get my head around it all and reading at https://github.com/thestk/rtmidi and I think something for Mac is missing (apparently defining __MAXOSX_CORE__ and associations to CoreMIDI, CoreAudio and CoreFramework) but I'm a bit clueless here so just shooting in the dark with trying to get it all loaded up properly.

If I add "#define __MACOSX_CORE__" to the RtMidi.h file I get two errors for RtMidi.cpp:
cast from 'const UInt8 *' (aka 'const unsigned char *') to 'const SInt32 *' (aka 'const int *') increases required alignment from 1 to 4 [-Werror,-Wcast-align] Line 1368
variable length arrays are a C99 feature [-Werror,-Wvla-extension] Line 1667

Am I missing anything obvious?

gumtown

Have you included the core libraries in your project file?

macx{
        LIBS += -framework CoreMidi -framework CoreAudio -framework CoreFoundation
        message("X-Code LIBRARIES SHOULD BE INSTALLED or ERROR will Occur")
}
Free "GR-55 FloorBoard" editor software from https://sourceforge.net/projects/grfloorboard/

StevenMartin

Is that specific to Qt? It's not something I'm using, but is Qt required for using RtMidi?

philjynx

Quote from: StevenMartin on May 09, 2021, 11:09:11 AM
Is that specific to Qt? It's not something I'm using, but is Qt required for using RtMidi?
No, it isn't.

Here https://www.music.mcgill.ca/~gary/rtmidi/ for an excellent tutorial on RtMidi

gumtown

Qt is not required for RtMidi as it is purely C/C++

as per the link philjynx posted, scroll down the page to the preprocessor definitions required for compiling,
you need to include x-code libraries:
-framework CoreMIDI
-framework CoreAudio
-framework CoreFoundation
Free "GR-55 FloorBoard" editor software from https://sourceforge.net/projects/grfloorboard/