Skip to content

Commit 6fc462f

Browse files
committed
RP2040, ESP8266
1 parent 966d9f4 commit 6fc462f

File tree

10 files changed

+54
-12
lines changed

10 files changed

+54
-12
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version=0.1
33
author=Phil Schatzmann
44
maintainer=Phil Schatzmann <[email protected]>
55
sentence=Arduino Audio Tools - Midi Support
6-
paragraph=Midi over Serial, Bluetooth, BLE and TCP/IP
6+
paragraph=Midi over Serial, Bluetooth, BLE and TCP/IP, Apple MIDI
77
category=Signal Input/Output
88
url=https://github.com/pschatzmann/arduino-midi
99
architectures=*

src/AppleMidiServer.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ bool AppleMidiServer :: begin(IPAddress adress, int control_port, int data_port_
3434
setupMDns(control_port);
3535
applemidi_init((apple_midi_cb_t) applemidi_callback_midi_message_received, (apple_midi_cb_t) applemidi_if_send_udp_datagram);
3636
int data_port = data_port_opt > 0 ? data_port_opt : control_port+1;
37-
MIDI_LOGI("MIDI using address: %s port: %d",adress.toString().c_str(), control_port);
37+
MIDI_LOGI("MIDI using address: %s port: %d",toStr(adress), control_port);
3838
// listen for udp on port
3939
udpControl.begin(control_port);
4040
udpData.begin(data_port);
@@ -43,6 +43,13 @@ bool AppleMidiServer :: begin(IPAddress adress, int control_port, int data_port_
4343
return status>=0;
4444
}
4545

46+
const char* AppleMidiServer :: toStr(IPAddress &adress){
47+
static char networ_str[10];
48+
//adress.toString() is not supported on all environemnts
49+
sprintf(networ_str,"%u.%u.%u.%u",adress[0],adress[1],adress[2],adress[3]);
50+
return networ_str;
51+
}
52+
4653
void AppleMidiServer :: end(){
4754
MIDI_LOGI( __PRETTY_FUNCTION__);
4855
udpControl.stop();

src/AppleMidiServer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,16 @@ class AppleMidiServer : public MidiCommon {
7373
virtual void writeData(MidiMessage *msg, int len);
7474
/// Setup MDNS apple-midi service
7575
virtual void setupMDns(int port);
76+
/// provides the network address as string
77+
const char* toStr(IPAddress &adress);
7678
/// Activate apple midi debug messages
7779
void setupLogger();
7880
/// Callback method to parse midi message
7981
static void applemidi_callback_midi_message_received(uint8_t port, uint32_t timestamp, uint8_t midi_status, uint8_t *remaining_message, size_t len, size_t continued_sysex_pos);
8082
/// Callback method to send UDP message with the help of the Arduino API
8183
static int32_t applemidi_if_send_udp_datagram(uint8_t *ip_addr, uint16_t port, uint8_t *tx_data, size_t tx_len);
8284

85+
8386
};
8487

8588
}

src/ConfigMidi.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
#pragma once
22

33
#define MIDI_ACTIVE true
4+
#define NAMESPACE_ACTIVE true
45

5-
#if defined(ESP32) || defined(ESP8266)
6+
#if defined(ESP32)
67
# define MIDI_BLE_ACTIVE true
78
# define APPLE_MIDI_ACTIVE true
89
# define MDNS_ACTIVE true
10+
# define UDP_ACTIVE true
11+
# define TCP_ACTIVE true
12+
#elif defined(ESP8266)
13+
# define MIDI_BLE_ACTIVE false
14+
# define APPLE_MIDI_ACTIVE true
15+
# define MDNS_ACTIVE false
16+
# define UDP_ACTIVE true
17+
# define TCP_ACTIVE true
918
#else
10-
# define APPLE_MIDI_ACTIVE false
19+
# define APPLE_MIDI_ACTIVE true
1120
# define MIDI_BLE_ACTIVE false
1221
# define MDNS_ACTIVE false
22+
# define UDP_ACTIVE true
23+
# define TCP_ACTIVE true
1324
#endif
1425

src/Midi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
#include "MidiBleClient.h"
88
#include "MidiBleServer.h"
99
#include "MidiBleParser.h"
10+
#if TCP_ACTIVE
1011
#include "MidiIpServer.h"
12+
#endif
13+
#if UDP_ACTIVE
1114
#include "MidiUdpServer.h"
15+
#endif
1216
#if APPLE_MIDI_ACTIVE
1317
#include "AppleMidiServer.h"
1418
#endif
19+
#if NAMESPACE_ACTIVE
1520
using namespace midi;
21+
#endif

src/MidiIpServer.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,25 @@ class MidiIpServer : public MidiServer {
3636
return false;
3737
}
3838

39-
p_wifi_server = new WiFiServer(serverPort);
39+
if (p_wifi_server==nullptr){
40+
p_wifi_server = new WiFiServer(serverPort);
41+
}
4042
p_wifi_server->begin();
4143
MIDI_LOGI("server started on port %d", serverPort);
4244
return true;
4345
}
4446

4547
void end() {
4648
if (p_wifi_server!=nullptr){
47-
p_wifi_server->stopAll();
49+
delete p_wifi_server;
50+
p_wifi_server = nullptr;
4851
}
4952
}
5053

5154
void loop() {
5255
if (p_wifi_server!=nullptr){
5356
if (!client.connected()){
54-
client = p_wifi_server->accept();
57+
client = p_wifi_server->available();
5558
if (client.connected()){
5659
MIDI_LOGI("MidiIpServer->connected");
5760
in.setup(&client, new MidiParser(p_action), true);

src/MidiUdp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#ifdef ESP32
2-
31
#include <MidiUdp.h>
2+
#ifdef MIDI_ACTIVE
3+
44
#include "MidiLogger.h"
55

66
namespace midi {

src/MidiUdp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22
#include "ArdConfig.h"
3-
#ifdef ESP32
3+
#ifdef MIDI_ACTIVE
44

55
#include <WiFi.h>
66
#include <WiFiClient.h>

src/apple-midi/applemidi.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
#include <stdio.h>
3737
#include <string.h>
3838
#include <sys/time.h>
39-
#include <arpa/inet.h>
40-
4139

4240
// from https://en.wikipedia.org/wiki/RTP-MIDI#Apple's_session_protocol
4341
#define APPLEMIDI_COMMAND_INVITATION 0x494e // IN

src/apple-midi/applemidi.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ extern "C" {
4040
#include <stdint.h>
4141
#include <string.h>
4242

43+
#ifndef htons
44+
#define htons(x) ( ((x)<< 8 & 0xFF00) | \
45+
((x)>> 8 & 0x00FF) )
46+
#define ntohs(x) htons(x)
47+
#endif
48+
49+
#ifndef htonl
50+
#define htonl(x) ( ((x)<<24 & 0xFF000000UL) | \
51+
((x)<< 8 & 0x00FF0000UL) | \
52+
((x)>> 8 & 0x0000FF00UL) | \
53+
((x)>>24 & 0x000000FFUL) )
54+
#define ntohl(x) htonl(x)
55+
#endif
56+
4357

4458
#ifndef APPLEMIDI_DEFAULT_DEBUG_LEVEL
4559
#define APPLEMIDI_DEFAULT_DEBUG_LEVEL 1

0 commit comments

Comments
 (0)