-
-
Save sbuller/1953623 to your computer and use it in GitHub Desktop.
Type based view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
class Display { | |
}; | |
class ncursesDisplay: public Display { | |
/* | |
* Print blits images to the output buffer, with an emphasis on font | |
* rendering. The class passed is the means of selecting the font, | |
* the particulars of this mechanism are not yet defined. | |
* | |
* A lineheight is assumed/provided for by the font, but length is | |
* specified to indicate how much space to clear, incase the text is | |
* short, and to clip the text incase it's long. | |
* | |
* The length, depending on the display type may need to be specified | |
* in characters, or in pixels. This is okay, as the design will be | |
* dependent on this distinction quite fundamentally. | |
* | |
* Font shall be an iterator that yields 'images'. | |
*/ | |
void print(int x, int y, int length, Text t); | |
void output(); | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
class Draw { | |
public: | |
Draw(ostream &out):out(out){} | |
template <class T> | |
friend Draw& operator<< (Draw &out, T t); | |
private: | |
ostream &out; | |
}; | |
template <class T> | |
Draw& operator<< (Draw &out, T t) | |
{ | |
out.out <<t; | |
return out; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
namespace FilterEnum { | |
enum Enum { | |
Sharp, | |
Slow | |
}; | |
} | |
typedef FilterEnum::Enum Filter; | |
namespace InputEnum { | |
enum Enum { | |
One, | |
Two, | |
Three, | |
Four, | |
Five, | |
Six | |
}; | |
} | |
typedef InputEnum::Enum Input; | |
namespace QuantizerEnum { | |
enum Enum { | |
SixBitTrueDifferential, | |
SevenBitPseudoDifferential, | |
SevenBitTrueDifferential, | |
EightBitPseudoDifferential, | |
EightBitTrueDifferential, | |
NineBitPseudoDifferential | |
}; | |
} | |
typedef QuantizerEnum::Enum Quantizer; | |
namespace DPLLBandwidthEnum { | |
enum Enum { | |
Lowest, | |
Low, | |
LowMedium, | |
Medium, | |
MediumHigh, | |
High, | |
Highest, | |
Best | |
}; | |
} | |
typedef DPLLBandwidthEnum::Enum Bandwidth; | |
namespace IIRFilterEnum { | |
enum Enum { | |
FortyThreeKHz, | |
PCM = FortyThreeKHz, | |
FiftyKHz, | |
SixtyKHz, | |
SeventyKHz | |
}; | |
} | |
typedef IIRFilterEnum::Enum IIRFilter; | |
typedef int SampleRate; | |
typedef bool OversampleFilter; | |
namespace InputModeEnum { | |
enum Enum { | |
I2S, | |
DSD, | |
SPDIF, | |
AutoI2SorDSD, | |
AutoSPDIF | |
}; | |
} | |
typedef InputModeEnum::Enum InputMode; | |
namespace NotchDelayEnum { | |
enum Enum { | |
None, | |
ClockBy4, | |
ClockBy8, | |
ClockBy16, | |
ClockBy32, | |
ClockBy64 | |
}; | |
} | |
typedef NotchDelayEnum::Enum NotchDelay; | |
namespace DPLLBandwidthModeEnum { | |
enum Enum { | |
X1, | |
X128, | |
Off | |
}; | |
} | |
typedef DPLLBandwidthModeEnum::Enum BandwidthMode; | |
struct Heartbeat {}; | |
struct Volume {}; | |
class Model { | |
public: | |
Input input; | |
Filter filter; | |
Quantizer quantizer; | |
Bandwidth bandwidth; | |
SampleRate sampleRate; | |
OversampleFilter oversampleFilter; | |
Volume volume; | |
IIRFilter iirFilter; | |
InputMode inputMode; | |
NotchDelay notchDelay; | |
BandwidthMode bandwidthMode; | |
Heartbeat heartbeat; | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "model.h" | |
#include "draw.h" | |
#define DRAW(type, exp) Draw& operator<< (Draw &out, type t)\ | |
{\ | |
return out <<exp;\ | |
} | |
#define DRAWLINE(line, type, exp) Draw& operator<< (Draw &out, Line<line, type> t)\ | |
{\ | |
return out <<exp;\ | |
} | |
#define LINE(line, exp) Line<line, decltype(exp)>(exp) | |
template <int l, class T> | |
struct Line { | |
Line(T t):t(t) {} | |
T t; | |
}; | |
DRAWLINE(0, Volume, "V1") | |
DRAWLINE(1, Volume, "V2") | |
DRAWLINE(2, Volume, "V3") | |
DRAWLINE(0, Heartbeat, "!") | |
DRAWLINE(1, Heartbeat, "@") | |
DRAWLINE(2, Heartbeat, "#") | |
DRAWLINE(3, Heartbeat, "$") | |
DRAW(Input, "PC-BST") | |
DRAW(Filter, "SHR") | |
DRAW(Quantizer, "9bP") | |
DRAW(Bandwidth, "BST") | |
DRAW(SampleRate, "44099") | |
DRAW(OversampleFilter, "^") | |
DRAW(IIRFilter, "PCM") | |
DRAW(NotchDelay, "/64") | |
DRAW(BandwidthMode, "NOR") | |
DRAW(InputMode, "i2S") | |
Draw& operator<< (Draw &out, Model m) | |
{ | |
out <<LINE(0,m.heartbeat) | |
<<m.input | |
<<" " <<m.inputMode | |
<<" " <<m.oversampleFilter | |
<<m.sampleRate | |
<<"\n"; | |
out <<LINE(1,m.heartbeat) | |
<<"Fi." <<m.filter | |
<<" " <<m.iirFilter | |
<<" " <<LINE(0,m.volume) | |
<<"\n"; | |
out <<LINE(2,m.heartbeat) | |
<<"PL." <<m.bandwidth | |
<<" " <<m.bandwidthMode | |
<<" " <<LINE(1,m.volume) | |
<<"\n"; | |
out <<LINE(3,m.heartbeat) | |
<<"Qz." <<m.quantizer | |
<<" " <<m.notchDelay | |
<<" " <<LINE(2,m.volume) | |
<<"\n"; | |
return out; | |
} | |
int main() | |
{ | |
Draw out(cout); | |
Model m; | |
out <<m; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment