diff --git a/src/App.js b/src/App.js index 8a0aee1..dab9ead 100644 --- a/src/App.js +++ b/src/App.js @@ -1,17 +1,7 @@ import './App.css'; -import { cantusFirmus, Pitch, mySequence } from './components/PitchLogic'; +import { cantusFirmus, mySequence } from './components/Instances'; function App() { - const handleTranspose = (cantus, amount) => { - let newFirmus = []; - for (let pitch of cantus) { - const thing = new Pitch(pitch.getNote() + amount); - newFirmus.push(thing); - } - console.log(newFirmus); - return newFirmus; - } - mySequence.getSonorities(); return ( diff --git a/src/components/Counterpoint.js b/src/components/Counterpoint.js new file mode 100644 index 0000000..0b45dbf --- /dev/null +++ b/src/components/Counterpoint.js @@ -0,0 +1,45 @@ +export default class Sequence { + // constructor receives an array of cantii; those at higher indices will be placed at higher pitch levels + // Sequence expects that each cantus is the same length + constructor(cantii) { + this.sequence = cantii; + this.sonorities = null; + } + + getSequence() { + 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(
{cantus.returnLetters()}
); + } + return output; + } + + getSonorities() { + // output is an array containing sonorities as raw, inner arrays + const output = []; + for (let i = 0; i < this.sequence[0].melody.length; i++) { + let thing = []; + for (let each of this.sequence) { + thing.push(each.melody[i].note); + } + output.push(thing); + } + console.log(output); + } + + evaluate() { + + } +} \ No newline at end of file diff --git a/src/components/Instances.js b/src/components/Instances.js new file mode 100644 index 0000000..f78b34c --- /dev/null +++ b/src/components/Instances.js @@ -0,0 +1,11 @@ +import Cantus from "./Melody"; +import Sequence from "./Counterpoint"; +import { cantusHelper } from "../util/util"; + +const cantusPitches = cantusHelper([3,6,5,3,8,6,10,8,6,5,3]); +export const cantusFirmus = new Cantus(cantusPitches); + +const solutionPitches = cantusHelper([10,10,8,10,12,1,1,12,3,2,3]) +export const cantusSolution = new Cantus(solutionPitches); + +export const mySequence = new Sequence([cantusFirmus, cantusSolution]); diff --git a/src/components/Melody.js b/src/components/Melody.js new file mode 100644 index 0000000..2f4725d --- /dev/null +++ b/src/components/Melody.js @@ -0,0 +1,30 @@ +import { letterNames } from "../util/util"; + +export default class Cantus { + constructor(notes) { + this.melody = notes; + this.head = null; + this.tail = null; + } + + getMelody() { + return this.melody; + } + + getHead() { + return this.head; + } + + getTail() { + return this.tail; + } + + returnLetters() { + let output = []; + for (let pitch of this.melody) { + let reduced = pitch.getNote() % 12; + output.push(`${letterNames[reduced]} `); + } + return output; + } +} \ No newline at end of file diff --git a/src/components/Pitch.js b/src/components/Pitch.js new file mode 100644 index 0000000..f4bea7c --- /dev/null +++ b/src/components/Pitch.js @@ -0,0 +1,29 @@ +export default class Pitch { + // constructor expects to receive an integer representing a pitch + constructor(note) { + this.note = note; + this.duration = 1; + this.next = null; + } + + getNote() { + return this.note; + } + + getDuration() { + return this.duration; + } + + upOctave() { + this.note += 12; + } + + downOctave() { + this.note -= 12; + } + + transposeByAmount(amount) { + // a positive int will transpose up, negative int will transpose down + this.note += amount; + } +} \ No newline at end of file diff --git a/src/components/PitchLogic.js b/src/components/PitchLogic.js deleted file mode 100644 index 74e156e..0000000 --- a/src/components/PitchLogic.js +++ /dev/null @@ -1,164 +0,0 @@ -export const letterNames = { - 0: 'B', - 1: 'C', - 2: 'C-sharp', - 3: 'D', - 4: 'D-sharp', - 5: 'E', - 6: 'F', - 7: 'F-sharp', - 8: 'G', - 9: 'G-sharp', - 10: 'A', - 11: 'A-sharp', -} - -export const harmony = { - 0: 'perfect', - 1: 'dissonance', - 2: 'imperfect', - 3: 'imperfect', - 4: 'imperfect', - 5: 'perfect', - 6: 'dissonance', - 7: 'perfect', - 8: 'imperfect', - 9: 'imperfect', - 10: 'imperfect', - 11: 'dissonance' -} - - -export class Pitch { - // constructor expects to receive an integer representing a pitch - constructor(note) { - this.note = note; - this.duration = 1; - } - - getNote() { - return this.note; - } - - getDuration() { - return this.duration; - } - - upOctave() { - this.note += 12; - } - - downOctave() { - this.note -= 12; - } - - transposeByAmount(amount) { - // a positive int will transpose up, negative int will transpose down - this.note += amount; - } -} - - - -export class Cantus { - constructor(notes) { - this.melody = notes; - } - - getMelody() { - return this.melody; - } - - returnLetters() { - let output = []; - for (let pitch of this.melody) { - let reduced = pitch.getNote() % 12; - output.push(`${letterNames[reduced]} `); - } - return output; - } -} - - - -export class Sonority { - // constructor receives an array of Pitch class objects - constructor(notes) { - this.sonority = notes; - this.numVoices = null; - this.consonance = null; - this.harmonicPull = null; - } - - getSonority() { - return this.sonority; - } - - setConsonance() { - this.consonance = 1; - } -} - - - -export class Sequence { - // constructor receives an array of cantii; those at higher indices will be placed at higher pitch levels - // Sequence expects that each cantus is the same length - constructor(cantii) { - this.sequence = cantii; - this.sonorities = null; - } - - getSequence() { - 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({cantus.returnLetters()}
); - } - return output; - } - - getSonorities() { - // output is an array containing sonorities as raw, inner arrays - const output = []; - for (let i = 0; i < this.sequence[0].melody.length; i++) { - let thing = []; - for (let each of this.sequence) { - thing.push(each.melody[i].note); - } - output.push(thing); - } - console.log(output); - } - - evaluate() { - - } -} - -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); - -const solutionPitches = cantusHelper([10,10,8,10,12,1,1,12,3,2,3]) -export const cantusSolution = new Cantus(solutionPitches); - -export const mySequence = new Sequence([cantusFirmus, cantusSolution]); diff --git a/src/components/Sonority.js b/src/components/Sonority.js new file mode 100644 index 0000000..d2aa5e6 --- /dev/null +++ b/src/components/Sonority.js @@ -0,0 +1,17 @@ +export default class Sonority { + // constructor receives an array of Pitch class objects + constructor(notes) { + this.sonority = notes; + this.numVoices = null; + this.consonance = null; + this.harmonicPull = null; + } + + getSonority() { + return this.sonority; + } + + setConsonance() { + this.consonance = 1; + } +} \ No newline at end of file diff --git a/src/util/util.js b/src/util/util.js new file mode 100644 index 0000000..cc029a3 --- /dev/null +++ b/src/util/util.js @@ -0,0 +1,49 @@ +import Pitch from '../components/Pitch'; + +export const cantusHelper = (arr) => { + let mappedArray = []; + for (let each of arr) { + mappedArray.push(new Pitch(each)); + } + return mappedArray; +} + +export const letterNames = { + 0: 'B', + 1: 'C', + 2: 'C-sharp', + 3: 'D', + 4: 'D-sharp', + 5: 'E', + 6: 'F', + 7: 'F-sharp', + 8: 'G', + 9: 'G-sharp', + 10: 'A', + 11: 'A-sharp', +} + +export const harmony = { + 0: 'perfect', + 1: 'dissonance', + 2: 'imperfect', + 3: 'imperfect', + 4: 'imperfect', + 5: 'perfect', + 6: 'dissonance', + 7: 'perfect', + 8: 'imperfect', + 9: 'imperfect', + 10: 'imperfect', + 11: 'dissonance' +} + +export const handleTranspose = (cantus, amount) => { + let newFirmus = []; + for (let pitch of cantus) { + const thing = new Pitch(pitch.getNote() + amount); + newFirmus.push(thing); + } + console.log(newFirmus); + return newFirmus; +} \ No newline at end of file