Skip to content

Commit

Permalink
Clsource scales (#157)
Browse files Browse the repository at this point in the history
* added scales

* Refactor fields in ProjectView

Re-use the same variable for all UIIntVarField

---------

Co-authored-by: Camilowser <[email protected]>
Co-authored-by: djdiskmachine <[email protected]>
  • Loading branch information
3 people authored Oct 22, 2024
1 parent 8816157 commit 3a8df09
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 31 deletions.
2 changes: 1 addition & 1 deletion projects/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ COMMONFILES := \
MessageBox.o \
GrooveView.o UINoteVarField.o UIBigHexVarField.o \
SRPUpdaters.o UIStaticField.o \
Song.o Chain.o Phrase.o Project.o \
Song.o Chain.o Phrase.o Project.o Scale.o \
char.o n_assert.o fixed.o wildcard.o \
SyncMaster.o TablePlayback.o Player.o \
Table.o TableView.o\
Expand Down
8 changes: 8 additions & 0 deletions projects/lgpt.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,14 @@
RelativePath="..\sources\Application\Model\Song.h"
>
</File>
<File
RelativePath="..\sources\Application\Model\Scale.cpp"
>
</File>
<File
RelativePath="..\sources\Application\Model\Scale.h"
>
</File>
<File
RelativePath="..\sources\Application\Model\Table.cpp"
>
Expand Down
2 changes: 2 additions & 0 deletions projects/lgpt.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
<ClCompile Include="..\sources\Application\Model\Project.cpp" />
<ClCompile Include="..\sources\Application\Model\Song.cpp" />
<ClCompile Include="..\sources\Application\Model\Table.cpp" />
<ClCompile Include="..\sources\Application\Model\Scale.cpp" />
<ClCompile Include="..\sources\UIFramework\BasicDatas\FontConfig.cpp" />
<ClCompile Include="..\sources\Application\views\ChainView.cpp" />
<ClCompile Include="..\sources\Application\views\ConsoleView.cpp" />
Expand Down Expand Up @@ -409,6 +410,7 @@
<ClInclude Include="..\sources\Application\Model\Project.h" />
<ClInclude Include="..\sources\Application\Model\Song.h" />
<ClInclude Include="..\sources\Application\Model\Table.h" />
<ClInclude Include="..\sources\Application\Model\Scale.h" />
<ClCompile Include="..\sources\UIFramework\BasicDatas\FontConfig.h" />
<ClInclude Include="..\sources\Application\views\ChainView.h" />
<ClInclude Include="..\sources\Application\views\ConsoleView.h" />
Expand Down
6 changes: 6 additions & 0 deletions projects/lgpt64.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
A95153FD2C88A4E70060FA44 /* SDLTimer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A95153FB2C88A4E60060FA44 /* SDLTimer.cpp */; };
A95154012C88A6670060FA44 /* MacOSmain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A95153FE2C88A6670060FA44 /* MacOSmain.cpp */; };
A95154052C88A6720060FA44 /* MacOSSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A95154042C88A6720060FA44 /* MacOSSystem.cpp */; };
A9A67DC42C9629AF00E923CD /* Scale.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A9A67DC32C9629AF00E923CD /* Scale.cpp */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -515,6 +516,8 @@
A95153FE2C88A6670060FA44 /* MacOSmain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MacOSmain.cpp; path = ../MacOS/MacOSMain/MacOSmain.cpp; sourceTree = "<group>"; };
A95154032C88A6720060FA44 /* MacOSSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MacOSSystem.h; path = ../../MacOS/MacOSSystem/MacOSSystem.h; sourceTree = "<group>"; };
A95154042C88A6720060FA44 /* MacOSSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MacOSSystem.cpp; path = ../../MacOS/MacOSSystem/MacOSSystem.cpp; sourceTree = "<group>"; };
A9A67DC22C9629AF00E923CD /* Scale.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Scale.h; sourceTree = "<group>"; };
A9A67DC32C9629AF00E923CD /* Scale.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Scale.cpp; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -762,6 +765,8 @@
737D11A20BCE66F000099CB3 /* Model */ = {
isa = PBXGroup;
children = (
A9A67DC32C9629AF00E923CD /* Scale.cpp */,
A9A67DC22C9629AF00E923CD /* Scale.h */,
87CA0EA80F7E1160001D6BD0 /* Mixer.cpp */,
87CA0EA90F7E1160001D6BD0 /* Mixer.h */,
73A640190D3CF90A00F43955 /* Groove.cpp */,
Expand Down Expand Up @@ -1509,6 +1514,7 @@
737D128D0BCE66F000099CB3 /* UIController.cpp in Sources */,
737D128E0BCE66F000099CB3 /* ViewData.cpp in Sources */,
737D12900BCE66F000099CB3 /* Observable.cpp in Sources */,
A9A67DC42C9629AF00E923CD /* Scale.cpp in Sources */,
737D12940BCE66F000099CB3 /* Service.cpp in Sources */,
737D12950BCE66F000099CB3 /* ServiceRegistry.cpp in Sources */,
737D12960BCE66F000099CB3 /* SubService.cpp in Sources */,
Expand Down
28 changes: 19 additions & 9 deletions sources/Application/Model/Project.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include "Project.h"
#include "Application/Instruments/SampleInstrument.h"
#include "Application/Instruments/SamplePool.h"
#include "Application/Persistency/PersistencyService.h"
#include "Application/Player/SyncMaster.h"
#include "Foundation/Variables/WatchedVariable.h"
#include "Groove.h"
#include "Scale.h"
#include "Services/Midi/MidiService.h"
#include "System/FileSystem/FileSystem.h"
#include "System/Console/Trace.h"
#include "System/FileSystem/FileSystem.h"
#include "System/io/Status.h"
#include "Foundation/Variables/WatchedVariable.h"
#include "Application/Player/SyncMaster.h"
#include "Table.h"
#include "Groove.h"
#include "Application/Persistency/PersistencyService.h"
#include "Application/Instruments/SamplePool.h"
#include "Application/Instruments/SampleInstrument.h"

#include "ProjectDatas.h"
#include <math.h>
Expand All @@ -32,9 +33,12 @@ tempoNudge_(0)
new Variable("softclip", VAR_SOFTCLIP, softclipStates, 5, 0);
this->Insert(softclip);
Variable *clipAttenuation =
new Variable("clipAttenuation", VAR_CLIP_ATTENUATION, 10);
new Variable("clipAttenuation", VAR_CLIP_ATTENUATION, 100);
this->Insert(clipAttenuation);

Variable *scale =
new Variable("scale", VAR_SCALE, scaleNames, scaleCount, 0);
this->Insert(scale);
scale->SetInt(0);

// Reload the midi device list

Expand Down Expand Up @@ -67,6 +71,12 @@ Project::~Project() {
delete instrumentBank_ ;
} ;

int Project::GetScale() {
Variable *v = FindVariable(VAR_SCALE);
NAssert(v);
return v->GetInt();
}

int Project::GetTempo() {
Variable *v=FindVariable(VAR_TEMPO) ;
NAssert(v) ;
Expand Down
4 changes: 3 additions & 1 deletion sources/Application/Model/Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define VAR_TRANSPOSE MAKE_FOURCC('T','R','S','P')
#define VAR_SOFTCLIP MAKE_FOURCC('S', 'F', 'T', 'C')
#define VAR_CLIP_ATTENUATION MAKE_FOURCC('C', 'A', 'T', 'N')
#define VAR_SCALE MAKE_FOURCC('S', 'C', 'A', 'L')

#define PROJECT_NUMBER "1"
#define PROJECT_RELEASE "4"
Expand All @@ -36,7 +37,8 @@ class Project: public Persistent,public VariableContainer,I_Observer {
bool Wrap() ;
void OnTempoTap();
void NudgeTempo(int value) ;
int GetTempo() ; // Takes nudging into account
int GetScale();
int GetTempo() ; // Takes nudging into account
int GetTranspose() ;
int GetSoftclip();
int GetAttenuation();
Expand Down
199 changes: 199 additions & 0 deletions sources/Application/Model/Scale.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
// from: https://github.com/xiphonics/picoTracker
#include "Scale.h"

// Source of scales in original release:
// https://upload.wikimedia.org/wikipedia/commons/thumb/3/35/PitchConstellations.svg/1280px-PitchConstellations.svg.png

// Additional Scales
// https://pianoencyclopedia.com/scales/

const char *scaleNotes[scaleNoteCount] = {
"C","C#","D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"
};

const char *scaleNames[scaleCount] = {"None (Chromatic)",
"Acoustic",
"Adonal malakh",
"Aeolian mode (minor)",
"Algerian",
"Altered",
"Augmented",
"Bebop dominant",
"Blues",
"Dorian",
"Double harmonic",
"Enigmatic",
"Flamenco",
"Gypsy",
"Half diminished",
"Harmonic major",
"Harmonic minor",
"Hirajoshi",
"Hungarian gypsy",
"Hungarian minor",
"Insen",
"Ionian mode (major)",
"Istrian",
"Iwato",
"Locrian",
"Lydian augmented",
"Lydian",
"Major bebop",
"Major locran",
"Major pentatonic",
"Melodic minor",
"Melodic minor (asc)",
"Minor pentatonic",
"Mixolydian",
"Neapolitan major",
"Neapolitan minor",
"Octatonic",
"Persian",
"Phrygian dominant",
"Phrygian",
"Prometheus",
"Ryukyu",
"Tritone",
"Tercera Alta",
"Ukranian",
"Whole tone",
};

const bool scaleSteps[scaleCount][scaleNoteCount] = {
// "C","C#","D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"
// "None (Chromatic)"
{true, true, true, true, true, true, true, true, true, true, true, true},
// "Acoustic"
{true, false, true, false, true, false, true, true, false, true, false,
false},
// "Adonal malakh"
{true, false, true, false, true, true, false, true, true, false, true,
false},
// "Aeolian mode (minor)"
{true, false, true, true, false, true, false, true, true, false, true,
false},
// "Algerian"
{true, false, true, true, false, false, true, true, true, false, false,
true},
// "Altered"
{true, true, false, true, true, false, true, false, true, false, true,
false},
// "Augmented"
{true, false, false, true, true, false, false, true, true, false, false,
true},
// "Bebop dominant"
{true, false, true, false, true, true, false, true, false, true, true,
true},
// "Blues"
{true, false, false, true, false, true, true, true, false, false, true,
false},
// "Dorian"
{true, false, true, true, false, true, false, true, false, true, true,
false},
// "Double harmonic"
{true, true, false, false, true, true, false, true, true, false, false,
true},
// "Enigmatic"
{true, true, false, false, true, false, true, false, true, false, true,
true},
// "Flamenco"
{true, true, false, false, true, true, false, true, true, false, false,
true},
// "Gypsy"
{true, false, true, true, false, false, true, true, true, false, true,
false},
// "Half diminished"
{true, false, true, true, false, true, true, false, true, false, true,
false},
// "Harmonic major"
{true, false, true, false, true, true, false, true, true, false, false,
true},
// "Harmonic minor"
{true, false, true, true, false, true, false, true, true, false, false,
true},
// "Hirajoshi"
{true, false, true, true, false, false, false, true, true, false, false,
false},
// "Hungarian gypsy"
{true, false, true, true, false, false, true, true, true, false, false,
true},
// "Hungarian minor"
{true, false, true, true, false, false, true, true, true, false, false,
true},
// "Insen"
{true, true, false, false, false, true, false, true, false, false, true,
false},
// "Ionian mode (major)"
{true, false, true, false, true, true, false, true, false, true, false,
true},
// "Istrian"
{true, true, false, true, true, false, true, true, false, false, false,
false},
// "Iwato"
{true, true, false, false, false, true, true, false, false, false, true,
false},
// "Locrian"
{true, true, false, true, false, true, true, false, true, false, true,
false},
// "Lydian augmented"
{true, false, true, false, true, false, true, false, true, true, false,
true},
// "Lydian"
{true, false, true, false, true, false, true, true, false, true, false,
true},
// "Major bebop"
{true, false, true, false, true, true, false, true, true, true, false,
true},
// "Major locran"
{true, false, true, false, true, true, true, false, true, false, true,
false},
// "Major pentatonic"
{true, false, true, false, true, false, false, true, false, true, false,
false},
// "Melodic minor"
{true, false, true, true, false, true, false, true, true, true, true, true},
// "Melodic minor (asc)"
{true, false, true, true, false, true, false, true, false, true, false,
true},
// "Minor pentatonic"
{true, false, false, true, false, true, false, true, false, false, true,
false},
// "Mixolydian"
{true, false, true, false, true, true, false, true, false, true, true,
false},
// "Neapolitan major"
{true, true, false, true, false, true, false, true, false, true, false,
true},
// "Neapolitan minor"
{true, true, false, true, false, true, false, true, true, false, false,
true},
// "Octatonic"
{true, false, true, true, false, true, true, false, true, true, false,
true},
// "Persian"
{true, true, false, false, true, true, true, false, true, false, false,
true},
// "Phrygian dominant"
{true, true, false, false, true, true, false, true, true, false, true,
false},
// "Phrygian"
{true, true, false, true, false, true, false, true, true, false, true,
false},
// "Prometheus"
{true, false, true, false, true, false, true, false, false, true, true,
false},
// Ryukyu
{true, false, false, false, true, true, false, true, false, false, false, true},
// "Tritone"
{true, true, false, false, true, false, true, true, false, false, true,
false},
// "Tercera Alta"
{false, true, true, false, false, false, true, false, false, true, false, false},
// "Ukranian"
{true, false, true, true, false, false, true, true, false, true, true,
false},
// "Whole tone"
{true, false, true, false, true, false, true, false, true, false, true,
false}

};
11 changes: 11 additions & 0 deletions sources/Application/Model/Scale.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// from: https://github.com/xiphonics/picoTracker
#ifndef SCALE_VIEW_H
#define SCALE_VIEW_H

const int scaleCount = 46;
const int scaleNoteCount = 12;
extern const char *scaleNames[scaleCount];
extern const char *scaleNotes[scaleNoteCount];
extern const bool scaleSteps[scaleCount][scaleNoteCount];

#endif
8 changes: 6 additions & 2 deletions sources/Application/Views/PhraseView.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "PhraseView.h"
#include "Application/Instruments/CommandList.h"
#include "Application/Model/Scale.h"
#include "Application/Model/Table.h"
#include "Application/Utils/HelpLegend.h"
#include "Application/Utils/char.h"
Expand Down Expand Up @@ -147,7 +148,6 @@ void PhraseView::updateCursorValue(ViewUpdateDirection direction, int xOffset,
lastCmd_ = *cc;
// Set legend
break;

case 3:
switch (direction) {
case VUD_RIGHT:
Expand Down Expand Up @@ -207,7 +207,11 @@ void PhraseView::updateCursorValue(ViewUpdateDirection direction, int xOffset,
}
if ((c) && (*c != 0xFF)) {
int offset = offsets_[col_ + xOffset][direction];

// Add/remove from offset to match selected scale
int scale = viewData_->project_->GetScale();
while (!scaleSteps[scale][(*c + offset) % 12]) {
offset > 0 ? offset++ : offset--;
}
updateData(c, offset, limit, wrap);
switch (col_ + xOffset) {
case 0:
Expand Down
Loading

0 comments on commit 3a8df09

Please sign in to comment.