defining some helper solutions

This commit is contained in:
2022-03-31 18:36:18 -05:00
parent cc68852e9b
commit 0c83722b40
2 changed files with 41 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
import './App.css'; import './App.css';
import { cantusFirmus, Pitch } from './components/PitchLogic'; import { cantusFirmus, Pitch, mySequence } from './components/PitchLogic';
function App() { function App() {
const handleTranspose = (cantus, amount) => { const handleTranspose = (cantus, amount) => {
@@ -22,6 +22,9 @@ function App() {
<h4>Cantus Firmus:</h4> <h4>Cantus Firmus:</h4>
<p className="monospaced">{cantusFirmus.returnLetters()}</p> <p className="monospaced">{cantusFirmus.returnLetters()}</p>
<h4>The provided solution:</h4>
<div>{mySequence.mapLayers()}</div>
</div> </div>
); );
} }

View File

@@ -46,7 +46,7 @@ export class Pitch {
export class Cantus { export class Cantus {
constructor(...notes) { constructor(notes) {
this.melody = notes; this.melody = notes;
} }
@@ -56,7 +56,7 @@ export class Cantus {
returnLetters() { returnLetters() {
let output = []; let output = [];
for (let pitch of this.melody[0]) { for (let pitch of this.melody) {
let reduced = pitch.getNote() % 12; let reduced = pitch.getNote() % 12;
output.push(`${letterNames[reduced]} `); output.push(`${letterNames[reduced]} `);
} }
@@ -68,8 +68,8 @@ export class Cantus {
export class Sonority { export class Sonority {
// constructor receives an array of Pitch class objects // constructor receives an array of Pitch class objects
constructor([...notes]) { constructor(notes) {
this.sonority = [...notes]; this.sonority = notes;
this.numVoices = null; this.numVoices = null;
this.consonance = null; this.consonance = null;
this.harmonicPull = null; this.harmonicPull = null;
@@ -87,27 +87,45 @@ export class Sonority {
export class Sequence { export class Sequence {
constructor(...cantii) { // constructor receives an array of cantii; those at higher indices will be placed at higher pitch levels
this.sequence = [...cantii]; // Sequence expects that each cantus is the same length
constructor(cantii) {
this.sequence = cantii;
} }
getSequence() { getSequence() {
return this.sequence; return this.sequence;
} }
checkLength() {
const lens = [];
for (let cantus of this.sequence) {
lens.push(cantus.melody.length);
}
return lens.reduce((a,b) => (a === b ? true : new Error("Length is not the same")));
}
mapLayers() {
let output = [];
for (let cantus of this.sequence) {
output.push(<p>{cantus.returnLetters()}</p>);
}
return output;
}
} }
const cantusHelper = (arr) => {
let mappedArray = [];
for (let each of arr) {
mappedArray.push(new Pitch(each));
}
return mappedArray;
}
const cantusPitches = cantusHelper([3,6,5,3,8,6,10,8,6,5,3]);
export const cantusFirmus = new Cantus(cantusPitches);
export const cantusFirmus = new Cantus([ const solutionPitches = cantusHelper([10,10,8,10,12,1,1,12,3,2,3])
new Pitch(3), // D export const cantusSolution = new Cantus(solutionPitches);
new Pitch(6), // F
new Pitch(5), // E export const mySequence = new Sequence([cantusFirmus, cantusSolution]);
new Pitch(3), // D
new Pitch(8), // G
new Pitch(6), // F
new Pitch(10), // A
new Pitch(8), // G
new Pitch(6), // F
new Pitch(5), // E
new Pitch(3) // D
]);