-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlgorithm.cpp
More file actions
66 lines (54 loc) · 1.51 KB
/
Algorithm.cpp
File metadata and controls
66 lines (54 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// Algorithm.cpp
// MusicalNoteOptimizer
//
// Created by Kaushik Naresh on 12/20/20.
// Copyright © 2020 Kaushik Naresh. All rights reserved.
//
#include "Algorithm.h"
#include "std_scales.h"
/*
First off, need to define what distance means
Using piano keys with the additional numbering, we create a way of calculating
a sort of 1 dimensional distance (for now)
1 'C'
1.5 'C#'/'Db'
2 'D'
2.5 'D#'/'Eb'
3 'E'
4 'F'
4.5 'F#'/'Gb'
5 'G'
5.5 'G#'/'Ab'
6 'A'
6.5 'A#'/'Bb'
7 'B'
DISCLAIMER: As of now, we are not taking musical sense into consideration...
So given these assigned values, we can calculate the absolute distance between them as being
how "far away" one note is from another
This keymapping is stored in the Scale class
*/
// dist
// args: first note (n_a), second note (n_b)
// return: distance between the two notes.
float Algo::dist(string n_a, string n_b)
{
return fabsf(xyz.note_val_access(n_a) - xyz.note_val_access(n_b));
}
// optimize
// args: the vector of notes to be optimized (notes), the scale to optimize to (scale)
// return: no return
void Algo::optimize(string_vec ¬es, Scale &scale, string_vec &result)
{
std::vector<std::vector <int> > opt;
opt.resize(7);
for(int i = 0; i < 7; i++)
{
opt[i].resize(notes.size());
}
for(int i = 0; i < 7; i++){
for(int j = 0; j < notes.size(); j++){
dist(scale.getNote(i), notes[j]);
}
}
}