Skip to content

Commit ac39b1f

Browse files
authored
Merge pull request #75 from pingdynasty/feature/screen-patch-class
Refactor screen handling and remove PLATFORM compilation setting
2 parents 44b15b8 + 04227a0 commit ac39b1f

13 files changed

Lines changed: 431 additions & 412 deletions

LibSource/ColourScreenPatch.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <cstddef>
2+
#include <string.h>
3+
#include "device.h"
4+
#include "ColourScreenPatch.h"
5+
#include "ProgramVector.h"
6+
#include "PatchProcessor.h"
7+
#include "ServiceCall.h"
8+
9+
PatchProcessor* getInitialisingPatchProcessor();
10+
11+
static void onDrawCallback(uint8_t* pixels, uint16_t width, uint16_t height){
12+
ColourScreenPatch* patch = (ColourScreenPatch*)getInitialisingPatchProcessor()->patch;
13+
if(patch != NULL){
14+
ColourScreenBuffer screen(width, height);
15+
screen.setBuffer(pixels);
16+
patch->processScreen(screen);
17+
}
18+
}
19+
20+
ColourScreenPatch::ColourScreenPatch(){
21+
void* drawArgs[] = {(void*)SYSTEM_FUNCTION_DRAW, (void*)&onDrawCallback};
22+
getProgramVector()->serviceCall(OWL_SERVICE_REGISTER_CALLBACK, drawArgs, 2);
23+
}
24+
25+
ColourScreenPatch::~ColourScreenPatch(){}
26+
27+
template<>
28+
Colour ColourScreenBuffer::getPixel(unsigned int x, unsigned int y){
29+
if(x >= width || y >= height)
30+
return 0;
31+
return pixels[y*width+x];
32+
}
33+
34+
template<>
35+
void ColourScreenBuffer::setPixel(unsigned int x, unsigned int y, Colour c){
36+
if(x < width && y < height)
37+
pixels[y*width+x] = c;
38+
}
39+
40+
template<>
41+
void ColourScreenBuffer::invertPixel(unsigned int x, unsigned int y){
42+
if(x < width && y < height)
43+
pixels[y*width+x] ^= WHITE;
44+
}
45+
46+
template<>
47+
void ColourScreenBuffer::fade(uint16_t steps){
48+
for(int i=0; i<height*width; ++i)
49+
pixels[i] =
50+
(((pixels[i] & RED) >> steps) & RED) |
51+
(((pixels[i] & GREEN) >> steps) & GREEN) |
52+
(((pixels[i] & BLUE) >> steps) & BLUE);
53+
}
54+
55+
template<>
56+
void ColourScreenBuffer::fill(Colour c) {
57+
for(int i=0; i<height*width; ++i)
58+
pixels[i] = c;
59+
}
60+

LibSource/ColourScreenPatch.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "Patch.h"
2+
#include "ScreenBuffer.h"
3+
4+
#define BLACK 0x0000
5+
#define BLUE 0x001F
6+
#define RED 0xF800
7+
#define GREEN 0x07E0
8+
#define CYAN 0x07FF
9+
#define MAGENTA 0xF81F
10+
#define YELLOW 0xFFE0
11+
#define WHITE 0xFFFF
12+
13+
typedef uint16_t Colour;
14+
typedef ScreenBuffer<uint16_t, BLACK, WHITE> ColourScreenBuffer;
15+
16+
/**
17+
* Abstract base class for patches that use a colour screen.
18+
* Colour format is 16 bits RGB565: RRRRR GGGGGG BBBBB
19+
* Compatible OLED drivers: SSD1331, SEPS1114A
20+
*/
21+
class ColourScreenPatch : public Patch {
22+
public:
23+
ColourScreenPatch();
24+
virtual ~ColourScreenPatch();
25+
uint16_t getScreenWidth();
26+
uint16_t getScreenHeight();
27+
virtual void processScreen(ColourScreenBuffer& screen) = 0;
28+
};
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
1-
#include "ScreenBuffer.h"
1+
#include <cstddef>
22
#include <string.h>
3-
#include <stddef.h>
4-
#include "font.c"
3+
#include "device.h"
4+
#include "MonochromeScreenPatch.h"
5+
#include "ProgramVector.h"
6+
#include "PatchProcessor.h"
7+
#include "ServiceCall.h"
58

6-
#if defined SSD1309
9+
#include "font.c" // todo load as resource
710

8-
Colour ScreenBuffer::getPixel(unsigned int x, unsigned int y){
11+
PatchProcessor* getInitialisingPatchProcessor();
12+
13+
static void onDrawCallback(uint8_t* pixels, uint16_t width, uint16_t height){
14+
MonochromeScreenPatch* patch = (MonochromeScreenPatch*)getInitialisingPatchProcessor()->patch;
15+
if(patch != NULL){
16+
MonochromeScreenBuffer screen(width, height);
17+
screen.setBuffer(pixels);
18+
patch->processScreen(screen);
19+
}
20+
}
21+
22+
MonochromeScreenPatch::MonochromeScreenPatch(){
23+
void* drawArgs[] = {(void*)SYSTEM_FUNCTION_DRAW, (void*)&onDrawCallback};
24+
getProgramVector()->serviceCall(OWL_SERVICE_REGISTER_CALLBACK, drawArgs, 2);
25+
}
26+
27+
MonochromeScreenPatch::~MonochromeScreenPatch(){}
28+
29+
template<>
30+
Colour MonochromeScreenBuffer::getPixel(unsigned int x, unsigned int y){
931
if(x >= width || y >= height)
1032
return 0;
1133
uint8_t ucByteOffset = 0;
@@ -19,7 +41,8 @@ Colour ScreenBuffer::getPixel(unsigned int x, unsigned int y){
1941
// return pixels[y*width+x];
2042
}
2143

22-
void ScreenBuffer::setPixel(unsigned int x, unsigned int y, Colour c){
44+
template<>
45+
void MonochromeScreenBuffer::setPixel(unsigned int x, unsigned int y, Colour c){
2346
if(x < width && y < height){
2447
uint8_t ucByteOffset = 0;
2548
uint16_t usiArrayLoc = 0;
@@ -35,7 +58,8 @@ void ScreenBuffer::setPixel(unsigned int x, unsigned int y, Colour c){
3558
}
3659
}
3760

38-
void ScreenBuffer::invertPixel(unsigned int x, unsigned int y){
61+
template<>
62+
void MonochromeScreenBuffer::invertPixel(unsigned int x, unsigned int y){
3963
if(x < width && y < height){
4064
uint8_t ucByteOffset = 0;
4165
uint16_t usiArrayLoc = 0;
@@ -52,7 +76,8 @@ void ScreenBuffer::invertPixel(unsigned int x, unsigned int y){
5276
}
5377
}
5478

55-
void ScreenBuffer::fade(uint16_t steps){
79+
template<>
80+
void MonochromeScreenBuffer::fade(uint16_t steps){
5681
// for(unsigned int i=0; i<height*width; ++i)
5782
// pixels[i] =
5883
// (((pixels[i] & RED) >> steps) & RED) |
@@ -63,43 +88,9 @@ void ScreenBuffer::fade(uint16_t steps){
6388
// todo: update contrast setting
6489
}
6590

66-
void ScreenBuffer::fill(Colour c) {
91+
template<>
92+
void MonochromeScreenBuffer::fill(Colour c) {
6793
memset(pixels, c, height*width/8);
6894
// for(unsigned int i=0; i<height*width; ++i)
6995
// pixels[i] = c;
7096
}
71-
72-
#elif defined SEPS114A
73-
74-
Colour ScreenBuffer::getPixel(unsigned int x, unsigned int y){
75-
if(x >= width || y >= height)
76-
return 0;
77-
return pixels[y*width+x];
78-
}
79-
80-
void ScreenBuffer::setPixel(unsigned int x, unsigned int y, Colour c){
81-
if(x < width && y < height)
82-
pixels[y*width+x] = c;
83-
}
84-
85-
void ScreenBuffer::invertPixel(unsigned int x, unsigned int y){
86-
if(x < width && y < height)
87-
pixels[y*width+x] ^= WHITE;
88-
}
89-
90-
void ScreenBuffer::fade(uint16_t steps){
91-
for(int i=0; i<height*width; ++i)
92-
pixels[i] =
93-
(((pixels[i] & RED) >> steps) & RED) |
94-
(((pixels[i] & GREEN) >> steps) & GREEN) |
95-
(((pixels[i] & BLUE) >> steps) & BLUE);
96-
}
97-
98-
void ScreenBuffer::fill(Colour c) {
99-
for(int i=0; i<height*width; ++i)
100-
pixels[i] = c;
101-
}
102-
103-
#else
104-
#error "Invalid screen configuration"
105-
#endif

LibSource/MonochromeScreenPatch.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "Patch.h"
2+
#include "ScreenBuffer.h"
3+
4+
#define BLACK 0
5+
#define WHITE 1
6+
7+
typedef uint8_t Colour;
8+
typedef ScreenBuffer<uint8_t, BLACK, WHITE> MonochromeScreenBuffer;
9+
10+
/**
11+
* Abstract base class for patches that use a monochrome screen.
12+
* Compatible OLED drivers: SSD1309
13+
*/
14+
class MonochromeScreenPatch : public Patch {
15+
public:
16+
MonochromeScreenPatch();
17+
virtual ~MonochromeScreenPatch();
18+
uint16_t getScreenWidth();
19+
uint16_t getScreenHeight();
20+
virtual void processScreen(MonochromeScreenBuffer& screen) = 0;
21+
};

LibSource/Patch.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,31 +75,6 @@ int Patch::getElapsedCycles(){
7575
return *DWT_CYCCNT;
7676
}
7777

78-
#ifdef USE_SCREEN
79-
void drawMessage(ScreenBuffer& screen){
80-
ProgramVector* pv = getProgramVector();
81-
if(pv->message != NULL){
82-
screen.setTextSize(1);
83-
screen.setTextWrap(true);
84-
screen.print(0, 26, pv->message);
85-
}
86-
}
87-
void drawTitle(const char* title, ScreenBuffer& screen){
88-
// draw title
89-
screen.setTextSize(2);
90-
screen.print(0, 16, title);
91-
}
92-
void Patch::processScreen(ScreenBuffer& screen){
93-
// screen.clear();
94-
const char* title = getInitialisingPatchProcessor()->getPatchName();
95-
drawTitle(title, screen);
96-
drawMessage(screen);
97-
// const char title[] = "KickBox";
98-
// screen.setTextSize(2);
99-
// screen.print(0, 16, title);
100-
}
101-
#endif /* USE_SCREEN */
102-
10378
#ifdef USE_MIDI_CALLBACK
10479
void Patch::processMidi(MidiMessage msg){}
10580

LibSource/Patch.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
#include "PatchParameter.h"
88
#include "SmoothValue.h"
99
#include "OpenWareMidiControl.h"
10-
#ifdef USE_SCREEN
11-
#include "ScreenBuffer.h"
12-
#endif /* USE_SCREEN */
1310

1411
#ifdef USE_MIDI_CALLBACK
1512
#include "MidiMessage.h"
@@ -68,11 +65,6 @@ class Patch {
6865
virtual void buttonChanged(PatchButtonId bid, uint16_t value, uint16_t samples){}
6966
/* virtual void parameterChanged(PatchParameterId pid, float value, int samples){} */
7067
virtual void processAudio(AudioBuffer& audio) = 0;
71-
#ifdef USE_SCREEN
72-
uint16_t getScreenWidth();
73-
uint16_t getScreenHeight();
74-
virtual void processScreen(ScreenBuffer& screen);
75-
#endif /* USE_SCREEN */
7668
#ifdef USE_MIDI_CALLBACK
7769
virtual void processMidi(MidiMessage msg);
7870
virtual void sendMidi(MidiMessage msg);

0 commit comments

Comments
 (0)