Skip to content

Commit b7067b9

Browse files
committed
clean unnecessary libs includes; add missing amplitude param to Synth class
1 parent 2194bce commit b7067b9

File tree

7 files changed

+40
-32
lines changed

7 files changed

+40
-32
lines changed

generator.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
//
88

99
#include "generator.h"
10+
#include "note.h"
1011
#include <vector>
1112
#include <math.h>
13+
#include <math.h>
14+
#include <cstdlib>
1215

1316
using namespace std;
1417

@@ -27,13 +30,19 @@ Gen& Gen::instance(vector<int> scale, function<vector<int>(void)> f) {
2730
double Gen::midi_to_freq(double midiNote) {
2831
return (pow(2, ((midiNote - 69.0) / 12)) * 440.0);
2932
}
33+
34+
double Gen::midi_to_amp(double midiNote) {
35+
double v = midiNote / 127.;
36+
37+
return v;
38+
}
3039

3140
note_t Gen::note() {
3241
vector<int> n = Gen::_f();
3342
note_t note;
34-
43+
3544
note.note = midi_to_freq(n[0] + 12 * n[3]);
36-
note.vel = n[1];
45+
note.vel = midi_to_amp(n[1]);
3746
note.dur = n[2];
3847

3948
return note;

generator.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,20 @@
99
#ifndef generator_h
1010
#define generator_h
1111

12-
#include <stdio.h>
1312
#include <vector>
1413
#include <functional>
1514

16-
using namespace std;
17-
18-
struct note_t {
19-
double note;
20-
int dur;
21-
int vel;
22-
int oct;
23-
};
15+
class note_t;
2416

2517
class Gen {
26-
static vector<int>_scale;
27-
static function<vector<int>(void)> _f;
18+
static std::vector<int>_scale;
19+
static std::function<std::vector<int>(void)> _f;
2820

2921
public:
30-
static Gen& instance(vector<int> scale, function<vector<int>(void)> f);
22+
static Gen& instance(std::vector<int> scale, std::function<std::vector<int>(void)> f);
3123
static double midi_to_freq(double midiNote);
24+
static double midi_to_amp(double midiNote);
3225
static note_t note();
3326
};
3427

35-
3628
#endif /* generator_h */

helpers.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#ifndef helpers_hpp
1010
#define helpers_hpp
1111

12-
#include <stdio.h>
13-
1412
namespace hlp {
1513
float rand(float min, float max);
1614
float midi_to_amp(int value);

sequencer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
//
77
//
88

9+
#include "maximilian.h"
10+
#include "note.h"
911
#include "sequencer.h"
12+
#include "generator.h"
13+
#include "synth.h"
1014

1115
maxiOsc Seq::_tick;
1216
float Seq::_tempo;
@@ -55,6 +59,5 @@ double Seq::output() {
5559
_note = _gen.note();
5660
lastCount = counter;
5761
}
58-
59-
return synth.output(_note.note);
62+
return synth.output(_note);
6063
}

sequencer.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@
99
#ifndef sequencer_h
1010
#define sequencer_h
1111

12-
#include <stdio.h>
13-
#include <vector>
14-
#include <functional>
15-
#include "generator.h"
16-
#include "synth.h"
17-
18-
using namespace std;
12+
class maxiOsc;
13+
class note_t;
14+
class Gen;
15+
class Synth;
1916

2017
class Seq {
2118
static maxiOsc _tick;
2219
static float _tempo;
2320
static int _pattern;
24-
static vector<int> _scale;
21+
static std::vector<int> _scale;
2522
static note_t _note;
26-
static function<vector<int>(void)> _f;
23+
static std::function<std::vector<int>(void)> _f;
2724
static Gen _gen;
2825

2926
public:
@@ -34,7 +31,7 @@ class Seq {
3431

3532
static Seq& instance();
3633
static Seq& start(float tempo, float pattern);
37-
static Seq& gen(vector<int> scale, std::function<vector<int>(void)> f);
34+
static Seq& gen(std::vector<int> scale, std::function<std::vector<int>(void)> f);
3835
static Seq& synthOut();
3936
static double output();
4037

synth.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88

99
#include "synth.h"
1010
#include "maximilian.h"
11+
#include "note.h"
1112

1213
maxiOsc _osc;
13-
14+
1415
double Synth::output(double freq) {
1516
return _osc.triangle(freq);
1617
}
18+
19+
double Synth::output(note_t note) {
20+
return _osc.triangle(note.note)*note.vel;
21+
}

synth.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@
99
#ifndef synth_h
1010
#define synth_h
1111

12-
#include <stdio.h>
1312
#include "maximilian.h"
1413

14+
class note_t;
15+
1516
class Synth {
1617
maxiOsc _osc;
1718

1819
public:
19-
Synth() {}
20+
Synth() {
21+
_osc.triangle(0);
22+
}
2023
double output(double freq);
24+
double output(note_t note);
2125
};
2226

2327
#endif /* synth_h */

0 commit comments

Comments
 (0)