Skip to content

Commit c46704b

Browse files
committed
Arduino Support
1 parent 009a98a commit c46704b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+270
-7419
lines changed

.vscode/settings.json

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"files.associations": {
3+
"iosfwd": "cpp",
4+
"__bit_reference": "cpp",
5+
"__config": "cpp",
6+
"__debug": "cpp",
7+
"__functional_base": "cpp",
8+
"__hash_table": "cpp",
9+
"__locale": "cpp",
10+
"__mutex_base": "cpp",
11+
"__nullptr": "cpp",
12+
"__split_buffer": "cpp",
13+
"__string": "cpp",
14+
"__threading_support": "cpp",
15+
"__tree": "cpp",
16+
"__tuple": "cpp",
17+
"algorithm": "cpp",
18+
"array": "cpp",
19+
"atomic": "cpp",
20+
"bitset": "cpp",
21+
"cctype": "cpp",
22+
"chrono": "cpp",
23+
"clocale": "cpp",
24+
"cmath": "cpp",
25+
"complex": "cpp",
26+
"condition_variable": "cpp",
27+
"cstdarg": "cpp",
28+
"cstddef": "cpp",
29+
"cstdint": "cpp",
30+
"cstdio": "cpp",
31+
"cstdlib": "cpp",
32+
"cstring": "cpp",
33+
"ctime": "cpp",
34+
"cwchar": "cpp",
35+
"cwctype": "cpp",
36+
"deque": "cpp",
37+
"exception": "cpp",
38+
"optional": "cpp",
39+
"string_view": "cpp",
40+
"fstream": "cpp",
41+
"functional": "cpp",
42+
"initializer_list": "cpp",
43+
"iomanip": "cpp",
44+
"ios": "cpp",
45+
"iostream": "cpp",
46+
"istream": "cpp",
47+
"iterator": "cpp",
48+
"limits": "cpp",
49+
"list": "cpp",
50+
"locale": "cpp",
51+
"map": "cpp",
52+
"memory": "cpp",
53+
"mutex": "cpp",
54+
"new": "cpp",
55+
"numeric": "cpp",
56+
"ostream": "cpp",
57+
"queue": "cpp",
58+
"random": "cpp",
59+
"ratio": "cpp",
60+
"set": "cpp",
61+
"sstream": "cpp",
62+
"stdexcept": "cpp",
63+
"streambuf": "cpp",
64+
"string": "cpp",
65+
"system_error": "cpp",
66+
"thread": "cpp",
67+
"tuple": "cpp",
68+
"type_traits": "cpp",
69+
"typeinfo": "cpp",
70+
"unordered_map": "cpp",
71+
"utility": "cpp",
72+
"vector": "cpp",
73+
"*.tcc": "cpp",
74+
"hash_map": "cpp",
75+
"cinttypes": "cpp",
76+
"hashtable": "cpp",
77+
"bit": "cpp",
78+
"compare": "cpp",
79+
"concepts": "cpp",
80+
"memory_resource": "cpp",
81+
"ranges": "cpp",
82+
"stop_token": "cpp"
83+
}
84+
}

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,22 @@ Download the project as zip and install the file in the Arduino IDE via -> Sketc
2424
git clone https://github.com/pschatzmann/Arduino-STK.git
2525
```
2626

27+
## Supported Processors
28+
29+
- ESP32 - The deveopment and testing has been done with the ESP32 so this will be the most stable and complete platform.
30+
- ESP8266 - I managed to have the code base compiling with the ESP8266 as well. This environment does not support Bluetooth.
31+
32+
You can consult the ArdConig.h file for the available functionality for your processor!
33+
34+
Standard Arduinos are not supported yet because the STK framwork is using the following (missing) classes which are not available
35+
in the Standard Arduino implementation:
36+
37+
- std::vector
38+
- std::string
39+
- std::ostringstream
40+
- std::cout
41+
- std::queue
42+
43+
I tried to compile the code with Mike Materas STL Library, but I unfortunatly there are some [open issues](https://github.com/arduino/ArduinoCore-avr/issues/287)
44+
2745

src/ADSR.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ void ADSR :: keyOff()
6666
void ADSR :: setAttackRate( StkFloat rate )
6767
{
6868
if ( rate < 0.0 ) {
69-
oStream_ << "ADSR::setAttackRate: argument must be >= 0.0!";
70-
handleError( StkError::WARNING ); return;
69+
handleError("ADSR::setAttackRate: argument must be >= 0.0!", StkError::WARNING ); return;
7170
}
7271

7372
attackRate_ = rate;
@@ -76,8 +75,7 @@ void ADSR :: setAttackRate( StkFloat rate )
7675
void ADSR :: setAttackTarget( StkFloat target )
7776
{
7877
if ( target < 0.0 ) {
79-
oStream_ << "ADSR::setAttackTarget: negative target not allowed!";
80-
handleError( StkError::WARNING ); return;
78+
handleError("ADSR::setAttackTarget: negative target not allowed!", StkError::WARNING ); return;
8179
}
8280

8381
target_ = target;
@@ -86,8 +84,7 @@ void ADSR :: setAttackTarget( StkFloat target )
8684
void ADSR :: setDecayRate( StkFloat rate )
8785
{
8886
if ( rate < 0.0 ) {
89-
oStream_ << "ADSR::setDecayRate: negative rates not allowed!";
90-
handleError( StkError::WARNING ); return;
87+
handleError("ADSR::setDecayRate: negative rates not allowed!", StkError::WARNING ); return;
9188
}
9289

9390
decayRate_ = rate;
@@ -96,8 +93,7 @@ void ADSR :: setDecayRate( StkFloat rate )
9693
void ADSR :: setSustainLevel( StkFloat level )
9794
{
9895
if ( level < 0.0 ) {
99-
oStream_ << "ADSR::setSustainLevel: negative level not allowed!";
100-
handleError( StkError::WARNING ); return;
96+
handleError("ADSR::setSustainLevel: negative level not allowed!", StkError::WARNING ); return;
10197
}
10298

10399
sustainLevel_ = level;
@@ -106,8 +102,7 @@ void ADSR :: setSustainLevel( StkFloat level )
106102
void ADSR :: setReleaseRate( StkFloat rate )
107103
{
108104
if ( rate < 0.0 ) {
109-
oStream_ << "ADSR::setReleaseRate: negative rates not allowed!";
110-
handleError( StkError::WARNING ); return;
105+
handleError("ADSR::setReleaseRate: negative rates not allowed!", StkError::WARNING ); return;
111106
}
112107

113108
releaseRate_ = rate;
@@ -119,8 +114,7 @@ void ADSR :: setReleaseRate( StkFloat rate )
119114
void ADSR :: setAttackTime( StkFloat time )
120115
{
121116
if ( time <= 0.0 ) {
122-
oStream_ << "ADSR::setAttackTime: negative or zero times not allowed!";
123-
handleError( StkError::WARNING ); return;
117+
handleError( "ADSR::setAttackTime: negative or zero times not allowed!", StkError::WARNING ); return;
124118
}
125119

126120
attackRate_ = 1.0 / ( time * Stk::sampleRate() );
@@ -129,8 +123,7 @@ void ADSR :: setAttackTime( StkFloat time )
129123
void ADSR :: setDecayTime( StkFloat time )
130124
{
131125
if ( time <= 0.0 ) {
132-
oStream_ << "ADSR::setDecayTime: negative or zero times not allowed!";
133-
handleError( StkError::WARNING ); return;
126+
handleError("ADSR::setDecayTime: negative or zero times not allowed!", StkError::WARNING ); return;
134127
}
135128

136129
decayRate_ = (1.0 - sustainLevel_) / ( time * Stk::sampleRate() );
@@ -139,8 +132,7 @@ void ADSR :: setDecayTime( StkFloat time )
139132
void ADSR :: setReleaseTime( StkFloat time )
140133
{
141134
if ( time <= 0.0 ) {
142-
oStream_ << "ADSR::setReleaseTime: negative or zero times not allowed!";
143-
handleError( StkError::WARNING ); return;
135+
handleError("ADSR::setReleaseTime: negative or zero times not allowed!", StkError::WARNING ); return;
144136
}
145137

146138
releaseRate_ = sustainLevel_ / ( time * Stk::sampleRate() );
@@ -158,8 +150,7 @@ void ADSR :: setAllTimes( StkFloat aTime, StkFloat dTime, StkFloat sLevel, StkFl
158150
void ADSR :: setTarget( StkFloat target )
159151
{
160152
if ( target < 0.0 ) {
161-
oStream_ << "ADSR::setTarget: negative target not allowed!";
162-
handleError( StkError::WARNING ); return;
153+
handleError( "ADSR::setTarget: negative target not allowed!", StkError::WARNING ); return;
163154
}
164155

165156
target_ = target;

src/ArdCompatibility.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
3+
4+
namespace std {
5+
6+
struct nothrow_t {};
7+
8+
}

src/ArdConfig.h

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,49 @@
77
*/
88

99
#if defined(ESP32)
10-
#define __VFS__ // raw files as compilable c arrays
11-
#define __RTOS__ // supports Free RTOS
12-
#define __LWIP__ // use lwip socket implementation
13-
#define __MIDI__ // support Midi
14-
#define __BLE_MIDI__ // support BLE
10+
#define __RAW_ARRAYS__ // raw files as compilable c arrays
11+
#define __STREAMS__ // output to Ardiono Streams
12+
#define __MIDI__ // support Midi
13+
#define __MIDI_BLE__ // support BLE
14+
#define __RTOS__ // supports Free RTOS
15+
#define __LWIP__ // use lwip socket implementation
1516
#define TASK_STACK_SIZE configMINIMAL_STACK_SIZE
16-
#define __STREAMS__ // output to Ardiono Streams
1717

1818
#undef PI
1919
#undef TWO_PI
2020

2121
#elif defined(ESP8266)
22-
#define __VFS__ // raw files as compilable c arrays
22+
#define __RAW_ARRAYS__
2323
#define __STREAMS__
24-
#define __NO_EXCEPTIONS__
25-
#define __NO_RT__
26-
// the call of stat is giving link errors, we deactivate the stat
27-
// function here with the effect that file based operations will not
28-
// work
29-
//#include "Arduino.h"
24+
#define __MIDI__
25+
#define __NO_EXCEPTIONS__ // comment out exceptions
26+
#define __NO_FSTREAM__ // No Messanger, MidiFileIn and Skini and FileRead
27+
3028
#include "FS.h"
3129
#undef PI
3230
#undef TWO_PI
3331
#undef round(x)
34-
32+
33+
#elif defined(ARDUINO)
34+
#define __ARDUINO__ // exclude standard c++ h files
35+
#define __STREAMS__ // output to Ardiono Streams
36+
#define __RAW_ARRAYS__ // raw files as compilable c arrays
37+
#define __MIDI__ // support Midi
38+
#define __NO_EXCEPTIONS__ // comment out exceptions
39+
#define __NO_FSTREAM__ // No Messanger, MidiFileIn and Skini and FileRead
40+
#define __NO_RT__ // no STK RT functions
41+
42+
#include <ArduinoSTL.h>
43+
44+
#undef PI
45+
#undef TWO_PI
46+
3547
#endif
3648

3749
// rtos must be loaded on top of other classes - so we add it here
50+
// rtos support is experimental and most things might not work. I recommend
51+
// that you do not use the netowrk functionality provided by the STK framework
52+
// but that you use the Standard Arduino functionality instead.
3853
#ifdef __RTOS__
3954
#include "FreeRTOS.h"
4055
#endif
41-
42-
43-
// #ifdef PI
44-
// #undef PI
45-
// #endif
46-
// #ifdef TWO_PI
47-
// #undef TWO_PI
48-
// #endif

src/ArdMidiBleClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "ArdConfig.h"
2-
#ifdef __MIDI__
2+
#ifdef __MIDI_BLE__
33
#ifndef ARD_MIDI_CLIENT_H
44
#define ARD_MIDI_CLIENT_H
55

src/ArdMidiBleEventHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "ArdConfig.h"
2-
#ifdef __BLE_MIDI__
2+
#ifdef __MIDI_BLE__
33
#ifndef ARDMIDIBLEEVENTHANDLER_H
44
#define ARDMIDIBLEEVENTHANDLER_H
55

src/ArdMidiBleServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "ArdConfig.h"
2-
#ifdef __MIDI__
2+
#ifdef __MIDI_BLE__
33
#ifndef ARDMIDIBLESERVER_H
44
#define ARDMIDIBLESERVER_H
55

src/ArdMidiCommon.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#include "ArdMidiCommon.h"
22
#ifdef ARDMIDICOMMON_H
33

4-
#define MIDI_SERVICE_UUID "03b80e5a-ede8-4b33-a751-6ce34ec4c700"
5-
#define MIDI_CHARACTERISTIC_UUID "7772e5db-3868-4112-a1a9-f2669d106bf3"
6-
74
namespace stk {
85

96
ArdMidiCommon::ArdMidiCommon(){

src/ArdMidiCommon.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#ifndef ARDMIDICOMMON_H
44
#define ARDMIDICOMMON_H
55

6-
#ifdef __BLE_MIDI__
6+
#ifdef __MIDI_BLE__
77
#include "sdkconfig.h"
88
#include <freertos/FreeRTOS.h>
99
#include <freertos/event_groups.h>
@@ -28,14 +28,17 @@
2828
#include "GeneralUtils.h"
2929
#include "esp_log.h"
3030
#include "BLE2902.h"
31+
32+
#define MIDI_SERVICE_UUID "03b80e5a-ede8-4b33-a751-6ce34ec4c700"
33+
#define MIDI_CHARACTERISTIC_UUID "7772e5db-3868-4112-a1a9-f2669d106bf3"
34+
3135
#endif
36+
3237
#include "Arduino.h"
3338
#include "Voicer.h"
3439
#include "ArdMidiEventHandler.h"
3540

3641

37-
#define MIDI_SERVICE_UUID "03b80e5a-ede8-4b33-a751-6ce34ec4c700"
38-
#define MIDI_CHARACTERISTIC_UUID "7772e5db-3868-4112-a1a9-f2669d106bf3"
3942

4043
namespace stk {
4144

src/ArdMidiStreamIn.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#ifndef ARDMIDISTREAMIN_H
2-
#define ARDMIDISTREAMIN_H
3-
41
#include "ArdConfig.h"
52
#ifdef __MIDI__
63

4+
#ifndef ARDMIDISTREAMIN_H
5+
#define ARDMIDISTREAMIN_H
6+
77
#include "ArdMidiCommon.h"
88
#include "ArdMidiEventHandler.h"
99

src/BeeThree.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "BeeThree.h"
3636
#include "ArdConfig.h"
3737

38-
#ifdef __VFS__
38+
#ifdef __RAW_ARRAYS__
3939
extern unsigned char *fwavblnk_raw, *sinewave_raw;
4040
extern unsigned int fwavblnk_raw_len,sinewave_raw_len;
4141
#endif
@@ -45,7 +45,7 @@ namespace stk {
4545
BeeThree :: BeeThree( void )
4646
: FM()
4747
{
48-
#ifdef __VFS__
48+
#ifdef __RAW_ARRAYS__
4949
for ( unsigned int i=0; i<3; i++ ){
5050
waves_[i] = new MemoryLoop( (Stk::rawwavePath() + "sinewave.raw").c_str(), sinewave_raw,sinewave_raw_len );
5151
}

src/Drummer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "Drummer.h"
1919
#include <cmath>
2020

21-
#ifdef __VFS__
21+
#ifdef __RAW_ARRAYS__
2222
extern const unsigned char dope_raw[], bassdrum_raw[], snardrum_raw[], tomlowdr_raw[], tommiddr_raw[],
2323
hihatcym_raw[], ridecymb_raw[], crashcym_raw[], cowbell1_raw[],tambourn_raw[];
2424
extern unsigned int dope_raw_len, bassdrum_raw_len, snardrum_raw_len, tomlowdr_raw_len, tommiddr_raw_len,
@@ -70,7 +70,7 @@ Drummer :: Drummer( void ) : Instrmnt()
7070
soundOrder_ = std::vector<int> (DRUM_POLYPHONY, -1);
7171
soundNumber_ = std::vector<int> (DRUM_POLYPHONY, -1);
7272

73-
#ifdef __VFS__
73+
#ifdef __RAW_ARRAYS__
7474
MemoryFS::registerFile("dope.raw",dope_raw,dope_raw_len);
7575
MemoryFS::registerFile("bassdrum.raw",bassdrum_raw,bassdrum_raw_len);
7676
MemoryFS::registerFile("snardrum.raw",snardrum_raw,snardrum_raw_len);

src/FM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ FM :: ~FM( void )
8686
void FM :: loadWaves( const char **filenames )
8787
{
8888
for (unsigned int i=0; i<nOperators_; i++ ) {
89-
#ifdef __VFS__
89+
#ifdef __RAW_ARRAYS__
9090
waves_[i] = new MemoryLoop( filenames[i] );
9191
#else
9292
waves_[i] = new FileLoop( filenames[i], true );

0 commit comments

Comments
 (0)