Dear colleagues,
I haven't communicated for a long time... The main reason is that I'm
trying to recruit new (active) contributors to this project. To this
end, I have contacted dozens of programmers/musicians/academics via my
LinkedIn network. The response has often been very positive, although so
far none of my contacts has taken the initiative to participate in the
development of the Bol Processor. My guess is that most of the competent
people are busy looking for (paid) jobs, or busy with other projects,
and the only people who could afford to work with us are (like me) old
programmers who do not feel like investing time in new technology. :-(
So… Suddenly I had the idea of hiring a new programmer who would
certainly tick all the boxes for effective participation... This is
ChatGPT!!! I had tried this platform for information search - very often
with wrong results, even invented, as very bad students do. But I saw
that it could also be asked to write code.
So I thought of the most urgent problem on BP3: to finish the
implementation of MIDI in real time. Something abominable in my mind,
but surely it can be solved simply by a programmer familiar with this
environment.
So I asked the following question... I haven't tried this code yet, but
it seems to be very meaningful, and most likely we can get it to do what
is needed in BP3 — though the input won't be a text file. If necessary,
ask more questions to our "colleague" ChatGPT!
Here it goes:
-------
QUESTION: Please write C code reading the name of a musical note (and
its octave number) from a text file and producing a message that will be
sent in real time to a MIDI device. Use CoreMIDI driver for this, and
include the code setting up CoreMIDI driver.
-------
ANSWER: To read the name of a musical note and its octave number from a
text file, you can use the standard C library functions to open, read,
and close a file. Here's an example code that reads a note and its
octave from a file named "note.txt":
-------
#include <stdio.h>
#include <stdlib.h>
#include <CoreMIDI/CoreMIDI.h>
int main()
{
// Set up CoreMIDI driver
MIDIClientRef midiClient;
MIDIClientCreate(CFSTR("MIDI Client"), NULL, NULL, &midiClient);
MIDIPortRef midiOutPort;
MIDIOutputPortCreate(midiClient, CFSTR("MIDI Output Port"),
&midiOutPort);
// Open file
FILE *file;
file = fopen("note.txt", "r");
if (file == NULL) {
printf("Error opening file.\n");
exit(1);
}
// Read note and octave
char note;
int octave;
fscanf(file, "%c%d", ¬e, &octave);
// Convert note and octave to MIDI note and send message to device
int midiNote = (octave + 1) * 12; // Middle C is MIDI note 60
switch (note) {
case 'C': midiNote += 0; break;
case 'D': midiNote += 2; break;
case 'E': midiNote += 4; break;
case 'F': midiNote += 5; break;
case 'G': midiNote += 7; break;
case 'A': midiNote += 9; break;
case 'B': midiNote += 11; break;
default: printf("Invalid note.\n"); exit(1);
}
MIDIPacketList packetList;
MIDIPacketListInit(&packetList);
MIDIPacket *packet = MIDIPacketListAdd(&packetList,
sizeof(packetList), NULL, 0, 3, NULL);
packet->data[0] = 0x90; // Note on
packet->data[1] = midiNote;
packet->data[2] = 127; // Velocity
packet->timeStamp = 0;
MIDISend(midiOutPort, NULL, &packetList);
// Close file and clean up CoreMIDI
fclose(file);
MIDIPortDispose(midiOutPort);
MIDIClientDispose(midiClient);
return 0;
}
-------
This code assumes that the text file "note.txt" contains a single line
with a note and its octave number, separated by a space, like this: "C4"
or "A5". The code converts the note and octave to a MIDI note number and
sends a MIDI "Note On" message with a velocity of 127 to the default
MIDI device.
-------
|