Reading from a USB device.

I have a Studio Logic MIDI music keyboard which I have plugged into my PC
via a USB cable. Windows has automatically installed the appropriate
driver/s. I am attempting to read the MIDI input from the keyboard as I
want to see if I can use a Macro to modify the sound before it goes to the
speaker. (Actually I want to try to programmatically mix sine waves like
a Hammond Organ does - it may not be possible, but I'd like to give it a
try!)

I installed a trial version of Device Monitoring Studio, see
https://www.hhdsoftware.com/device-monitoring-studio which enables me to
trap the raw data from the keyboard, and I'm able to identify which keys
are pressed or released, and also the keyboard sliders' movements and
slider positions. For my purposes, that is all I need to extract from the
MIDI stream.

I then went on the Web to see if I could find examples of Macro code that
would enable my program to emulate what I had been able to do with Device
Monitoring Studio. It turns out that USB coding is very complex and the
only examples I could find were in C, C++ or Visual Basic, none of which I
have, or have ever worked with.

I then had a look at LibreOffice 5.3 SDK API. I believe that is the API
that Base uses, and over several years I have developed a number of
databases using macros that make calls to the API. One API service I found
was, com.sun.star.io.pipe, which looks as though it might be what I need,
but I don't know if it would work with a USB port, and I could not find any
macro code examples that might point me in the right direction.

So my questions are -
1. Does anyone know if it is possible to read from a USB port using a
LibreOffice macro utilising the API? If so can you point me to some
example code (preferably in Basic)?
2. Failing that, is there a simple application on the market that can read
a USB MIDI stream into a buffer or file? I think Device Monitoring Studio
can do that, but it is expensive and has far more features than I'll ever
need.

Any help in this regard would be much appreciated

Thanks,

Noel

​Maybe I misunderstood something, but I don't see how this is related to
LibreOffice in any way. While it is true that it is possible to write
applications with LibreOffice to some extent, what you're describing would
be better done using anything else​.

Using Python with libusb could work, if you're looking for something quick
to implement and don't want to dwelve in compiled languages.

I seem to remember from years' ago that there was a free utility called
MidiOx for Windows that could read incoming midi streams. The website
still exists but it looks as though it might not have been further
developed recently : http://www.midiox.com/

Philip

You may want to take a look at Realterm

Realterm is an engineers terminal program specially designed for capturing, controlling and debugging binary and other difficult data streams. It is the best tool for debugging comms.

Post-Processing capture file is just one of many things it can do.

https://realterm.sourceforge.io/

I have not used it to analyze MIDI, but if there's data, it will see it.

Hope this helps.

Paul

I have a Studio Logic MIDI music keyboard which I have plugged into my PC
via a USB cable. Windows has automatically installed the appropriate
driver/s. I am attempting to read the MIDI input from the keyboard as I
want to see if I can use a Macro to modify the sound before it goes to the
speaker. (Actually I want to try to programmatically mix sine waves like
a Hammond Organ does - it may not be possible, but I'd like to give it a
try!)

...

​Maybe I misunderstood something, but I don't see how this is related to
LibreOffice in any way. While it is true that it is possible to write

If all you have is a hammer, everything looks like a nail :-}

I think the OP sounds muddled. Recording midi signals isn't going to help (much) with a wish to "programmatically mix sine waves" -- chalk and cheese, I think. Which thinking is amplified by the bit about "modify the sound before it goes to the speaker". I doubt (nay, hope) LO will ever offer a full-blown synth!!

I /think/ the OP is looking at a midi synthesiser plus a mixer. A doddle on linux to sling something together -- I'd be looking at qsynth, jack and jack_mixer as a start point. Maybe they'll run on windows..... I'd not know. I'd most certainly /not/ be looking to do any usb-level programming; that bit's already been done.

Or maybe I've totally mis-understood.

The article below will probably help quite a bit setting up.

https://nerdclub-uk.blogspot.com/2017/04/messing-about-with-midi-and-realterm-vs.html

The parts on Realterm and MIDI starts about half way down the article.

seems to me is you were using linux this should be almost automatic /dev/device.. <

  18.1 Device Files

UNIX has a beautifully consistent method of allowing programs to access hardware. Under UNIX, every piece of hardware is a file. To demonstrate this novelty, try viewing the file /dev/hda (you will have to be root to run this command):

  >less -f /dev/hda|

/dev/hda is not really a file at all. When you read from it, you are actually reading directly from the first physical hard disk of your machine. /dev/hda is known as a device file, and all of them are stored under the /dev directory.

Device files allow access to hardware. If you have a sound card installed and configured, you can try:

  >cat /dev/dsp > my_recording|

Say something into your microphone and then type:

  >cat my_recording > /dev/dsp|

The system will play out the sound through your speakers (note that this d\n always work, since the recording volume or the recording speed may not be set correctly.)

If no programs are currently using your mouse, you can also try:

  >cat /dev/mouse|

If you now move the mouse, the mouse protocol commands will be written directly to your screen (it will look like garbage). This is an easy way to see if your mouse is working, and is especially useful for testing serial port. Occasionally this test doesn't work because some command has previously configured the serial port in some odd way. In that case, also try:

  >cu -s 1200 -l /dev/mouse|

At a lower level, programs that access device files do so in two basic ways:

  * They read and write to the device to send and retrieve bulk data
    (much like less and cat above).
  * They use the *C* ioctl (/IO Control/) function to configure the
    device. (In the case of the sound card, this might set mono versus
    stereo, recording speed or other parameters.)

Because every kind of device that one can think of (except for network cards) can be twisted to fit these two modes of operation, UNIX's scheme has endured since its inception and is the universal method of accessing hardware.

  I think the interest to use Libre Office maybe to get the port data to be captured into a spreadsheet.. ?