This repository was archived by the owner on Feb 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMidiServer.h
More file actions
63 lines (53 loc) · 1.74 KB
/
MidiServer.h
File metadata and controls
63 lines (53 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//Midi Server using RtMidi
//Step1 Setup & configure midi device
//step2 read inputs from midi device
//step3 listen for connecting clients
//step4 send midi data to client
#pragma once
//c libraries must be used for some of the operations used
//so these need to be brought in as c++ equivs of old c headers
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <iostream>
#include <fstream>
#include <vector>
// external libraries used
#include "rtmidi-3.0.0/RtMidi.h"
using namespace std;
class MidiServer{
protected:
static const unsigned int buffer_size = 4096;
unsigned char buffer[buffer_size]; //buffer used by server to send messages
std::vector<unsigned char> midiBuffer; //buffer used by midi to read input
int server_fd, client_fd;
int valread;
struct sockaddr_in address;
int portno;
RtMidiIn *midi;
int configurePort();
int bindServer();
void clearBuffer();
int awaitConnection();
//when a server succesfully connects to a client the greeting should be sent
//greeting says hello from server, hello from client.
//server then displays the connected midi devices on the server side
//client response should be the port number they wish to listen to
//server and client then exchange midi information and responses.
int sendGreeting();
int sendMidiPortInformation();
int configureMidiPort();
int readMidiInput();//read from bound port
static void convertMidiInput(double deltatime, std::vector< unsigned char > *message, void *userData);//send to client (callback)
void sendMidiInput(string &message); //called by convert
void sendSuccess();
public:
MidiServer();
MidiServer(int portNum);
void startServer();
~MidiServer();
};