-
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
6 changed files
with
135 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import classNames from "classnames" | ||
import { Note, Scale } from "mtts" | ||
import { COLOR, getNoteColor } from "../../scale-builder/helpers/getNoteColor" | ||
|
||
export interface PianoBlackKeyComponentProps { | ||
note: Note, | ||
scale: Scale, | ||
} | ||
|
||
export interface PianoKeyComponentProps { | ||
note: Note, | ||
scale: Scale | ||
} | ||
|
||
interface PianoKeyProps { | ||
note: Note, | ||
scale: Scale, | ||
blackNote?: Note | undefined, | ||
PianoBlackKeyComponent?: React.FunctionComponent<PianoBlackKeyComponentProps>, | ||
PianoKeyComponent?: React.FunctionComponent<PianoKeyComponentProps> | ||
} | ||
|
||
export default function PianoKey({ note, scale, blackNote, PianoBlackKeyComponent, PianoKeyComponent }: PianoKeyProps) { | ||
return ( | ||
<div className={classNames({ | ||
'text-center flex align-items border rounded-bl rounded-br grow relative border-mtts-dark-violet-200': true, | ||
})}> | ||
{ | ||
PianoKeyComponent !== undefined && <PianoKeyComponent scale={scale} note={note} /> | ||
} | ||
{ | ||
blackNote && ( | ||
<div className={classNames({ | ||
'absolute w-1/2 h-1/2 translate-x-3/2 z-10 rounded-bl rounded-br border border-mtts-dark-violet-200 bg-mtts-dark-violet': true, | ||
})}> | ||
{ PianoBlackKeyComponent !== undefined && <PianoBlackKeyComponent scale={scale} note={blackNote} /> } | ||
</div> | ||
) | ||
} | ||
</div> | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Note, Scale } from "mtts" | ||
import PianoKey, { PianoBlackKeyComponentProps, PianoKeyComponentProps } from "./PianoKey" | ||
|
||
interface PianoRollProps { | ||
domain?: [Note, Note], | ||
scale?: Scale, | ||
PianoBlackKeyComponent?: React.FunctionComponent<PianoBlackKeyComponentProps>, | ||
PianoKeyComponent?: React.FunctionComponent<PianoKeyComponentProps> | ||
} | ||
|
||
export default function PianoRoll({ | ||
domain = [Note.fromSPN('A0'), Note.fromSPN('C5')], | ||
scale, | ||
PianoBlackKeyComponent, | ||
PianoKeyComponent | ||
}: PianoRollProps) { | ||
const notesWithinDomainRange = Array.from(Array(Note.getSemitonesBetween(domain[0], domain[1])).keys()).map((i) => { | ||
return Note.fromSPN(domain[0].SPN).sharpenChromatically(i) | ||
}) | ||
|
||
const whiteNotes = notesWithinDomainRange.filter(note => !note.hasAccidental()) | ||
const blackNotes = notesWithinDomainRange.filter(note => note.hasAccidental()) | ||
|
||
return ( | ||
<div className="w-full h-full"> | ||
<div className="h-full w-full flex flex-row"> | ||
{whiteNotes.map(note => ( | ||
<PianoKey | ||
key={`keys-key-${note.SPN}`} | ||
scale={scale} | ||
note={note} | ||
blackNote={blackNotes.find(blackNote => Note.getSemitonesBetween(note, blackNote) === 1)} | ||
PianoBlackKeyComponent={PianoBlackKeyComponent} | ||
PianoKeyComponent={PianoKeyComponent} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} |
18 changes: 18 additions & 0 deletions
18
app/projects/mtts/scale-builder/components/PianoBlackKey.tsx
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react' | ||
import { Note, Scale } from "mtts" | ||
import { PianoBlackKeyComponentProps } from "../../components/keys/PianoKey" | ||
import classNames from 'classnames' | ||
import { COLOR, getNoteColor } from '../helpers/getNoteColor' | ||
|
||
export default function PianoBlackKey({ scale, note }: PianoBlackKeyComponentProps) { | ||
return <div className={classNames({ | ||
'h-full w-full': true, | ||
'bg-mtts-cta-0': getNoteColor(scale, note) === COLOR.DEFAULT, | ||
'bg-mtts-yellow': getNoteColor(scale, note) === COLOR.YELLOW, | ||
'bg-mtts-khaki': getNoteColor(scale, note) === COLOR.KHAKI, | ||
'bg-mtts-green': getNoteColor(scale, note) === COLOR.GREEN, | ||
'bg-mtts-blue': getNoteColor(scale, note) === COLOR.BLUE, | ||
'bg-mtts-violet': getNoteColor(scale, note) === COLOR.VIOLET, | ||
'bg-mtts-red': getNoteColor(scale, note) === COLOR.RED, | ||
})}></div> | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react' | ||
import { PianoKeyComponentProps } from "../../components/keys/PianoKey" | ||
import classNames from 'classnames' | ||
import { COLOR, getNoteColor } from '../helpers/getNoteColor' | ||
|
||
export default function PianoKey({ scale, note }: PianoKeyComponentProps) { | ||
console.log(scale, note) | ||
return <div className={classNames({ | ||
'h-full w-full': true, | ||
'bg-mtts-cta-0': getNoteColor(scale, note) === COLOR.DEFAULT, | ||
'bg-mtts-yellow': getNoteColor(scale, note) === COLOR.YELLOW, | ||
'bg-mtts-khaki': getNoteColor(scale, note) === COLOR.KHAKI, | ||
'bg-mtts-green': getNoteColor(scale, note) === COLOR.GREEN, | ||
'bg-mtts-blue': getNoteColor(scale, note) === COLOR.BLUE, | ||
'bg-mtts-violet': getNoteColor(scale, note) === COLOR.VIOLET, | ||
'bg-mtts-red': getNoteColor(scale, note) === COLOR.RED, | ||
})}></div> | ||
} |
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