-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
148 additions
and
48 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
#pragma once | ||
#include "Signal.h" | ||
#include <array> | ||
#include "Signal.h" | ||
|
||
class Chord : public Signal | ||
{ | ||
public: | ||
Chord(std::string chord, std::array<double, 25> scale, std::string scaleType); | ||
|
||
private: | ||
/* The representation of a chord, e.g. I--, vi.., etc */ | ||
std::string chord; | ||
|
||
/* Key signature */ | ||
std::array<double, 25> scale; | ||
|
||
/* Major or Minor */ | ||
std::string scaleType; | ||
|
||
static std::string getChordSymbol(std::string chord); | ||
void setWaveTable(); | ||
static std::string toUpper(std::string string); | ||
/* Chord symbol without the duration syntax, e.g. I, IVd, iii, etc. */ | ||
std::string getChordSymbol(std::string chord); | ||
|
||
/* Set the wavetable */ | ||
void setWavetable(); | ||
|
||
/* Turn all characters in the string to uppercase letters */ | ||
std::string toUpper(std::string string); | ||
}; |
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,96 @@ | ||
#pragma once | ||
#include <map> | ||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
#include <memory> | ||
|
||
class Signal | ||
{ | ||
public: | ||
/* Beats per minute */ | ||
static double BPM; | ||
|
||
/* The lower part of time signature */ | ||
static double timeSignatureLower; | ||
|
||
/* Frequency of every note in the first octave */ | ||
const static double FIRST_OCTAVE_FREQ[7]; | ||
|
||
/* The Lookup Table used to generate signals */ | ||
const static std::vector<double> LUT; | ||
|
||
/* The position of each note in the major scale (1 means the key, 3 means 2 half-steps from the key, etc. */ | ||
const static int MAJOR_SCALE_STEPS[7]; | ||
|
||
/* The position of each note in the minor scale (1 means the key, 3 means 2 half-steps from the key, etc.) */ | ||
const static int MINOR_SCALE_STEPS[7]; | ||
|
||
/* The musical alphabet */ | ||
const static char OCTAVE[7]; | ||
|
||
/* Roman numbers from 1 to 7 */ | ||
const static std::string ROMAN_NUMBERS[7]; | ||
|
||
/* Sample rate */ | ||
const static int SAMPLE_RATE = 44100; | ||
|
||
/* Default constructor, the wavetable is set to an empty vector */ | ||
Signal(); | ||
|
||
/* The wavetable is set to a specific frequency and duration */ | ||
Signal(double freq, double duration); | ||
|
||
void add(Signal* signal); | ||
void append(Signal* signal); | ||
|
||
/* Get the data point at current phase */ | ||
double get(); | ||
|
||
/* Get the duration of the signal */ | ||
double getDuration(); | ||
|
||
/* Get the phase of the signal */ | ||
double getPhase(); | ||
std::vector<double> getWaveTable(); | ||
|
||
/* Get the wavetable of the signal */ | ||
std::vector<double> getWavetable(); | ||
|
||
/* Increment the phase of the signal */ | ||
void incrementPhase(); | ||
|
||
/* Return true if the wavetable is empty */ | ||
bool isEmpty(); | ||
void normalize(); | ||
void setWaveTable(double freq, double duration); | ||
|
||
static std::vector<double> createGuitarLUT(int size); | ||
static std::vector<double> createSineLUT(int size); | ||
static std::vector<double> createWaveTable(double freq, double duration); | ||
static double getDuration(std::string input); | ||
static double getNoteFreq(std::string name); | ||
/* Set the lower part of time signature and beats per minute */ | ||
static void setTimeSignatureLowerAndBPM(std::string timeSignatureLower, std::string BPM); | ||
|
||
/* Set the wavetable to a specific frequency and duration */ | ||
void setWavetable(double freq, double duration); | ||
|
||
protected: | ||
/* The wavetable of the signal */ | ||
std::unique_ptr<std::vector<double>> waveTable = std::unique_ptr<std::vector<double>>(new std::vector<double>); | ||
|
||
/* The phase of the signal (an index of a value in the wavetable) */ | ||
int phase = 0; | ||
|
||
/* Add a signal to this signal */ | ||
void add(Signal* signal); | ||
|
||
/* Append a signal to this signal */ | ||
void append(Signal* signal); | ||
|
||
/* Normalize the signal so that the highest amplitude is 1 */ | ||
void normalize(); | ||
|
||
/* Create a Lookup Table for the signal that guitar produces */ | ||
static std::vector<double> createGuitarLUT(int size); | ||
|
||
/* Create a Lookup Table for the signal that guitar produces */ | ||
static std::vector<double> createSineLUT(int size); | ||
|
||
/* Create a Lookup Table a sine wave */ | ||
static std::vector<double> createWavetable(double freq, double duration); | ||
|
||
/* Get the intended duration from an input */ | ||
static double getDuration(std::string input); | ||
|
||
/* Get the frequency of a note */ | ||
static double getNoteFreq(std::string name); | ||
}; |
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
Oops, something went wrong.