diff --git a/front/Navigation.tsx b/front/Navigation.tsx index 0869719..71efac4 100644 --- a/front/Navigation.tsx +++ b/front/Navigation.tsx @@ -16,7 +16,6 @@ import { Center } from 'native-base'; import LoadingComponent from './components/Loading'; import ProfileView from './views/ProfileView'; import useColorScheme from './hooks/colorScheme'; -import VirtualPiano from './components/VirtualPiano/VirtualPiano'; const Stack = createNativeStackNavigator(); @@ -42,8 +41,6 @@ export const Router = () => { }); const colorScheme = useColorScheme(); - return - return ( [0] & { showNoteNames: NoteNameBehavior; // default "onpress" highlightedNotes: Array; showOctaveNumbers: boolean; + style: StyleProp; }; const VirtualPiano = ({ @@ -33,6 +35,7 @@ const VirtualPiano = ({ showNoteNames, highlightedNotes, showOctaveNumbers, + style, }: VirtualPianoProps) => { const notesList: Array = [ Note.C, @@ -49,19 +52,20 @@ const VirtualPiano = ({ octaveList.push(octaveNum); } + const octaveWidthExpr = `calc(100% / ${octaveList.length})`; + return ( - + {octaveList.map((octaveNum) => { return ( n.key.octave ? n.key.octave == octaveNum : true + highlightedNotes={highlightedNotes.filter((n) => + n.key.octave ? n.key.octave == octaveNum : true )} startNote={octaveNum == startOctave ? startNote : notesList[0]} endNote={ @@ -77,22 +81,16 @@ const VirtualPiano = ({ }; VirtualPiano.defaultProps = { - onNoteDown: (n) => { - console.log("Note down: " + keyToStr(n)); - }, - onNoteUp: (n) => { - console.log("Note up: " + keyToStr(n)); - }, + onNoteDown: (_n: PianoKey) => {}, + onNoteUp: (_n: PianoKey) => {}, startOctave: 2, startNote: Note.C, endOctave: 6, endNote: Note.C, showNoteNames: NoteNameBehavior.onpress, - highlightedNotes: [ - { key: strToKey("D3") }, - { key: strToKey("A#"), bgColor: "#00FF00" }, - ], + highlightedNotes: [], showOctaveNumbers: true, + style: {}, }; export default VirtualPiano; diff --git a/front/views/PlayView.tsx b/front/views/PlayView.tsx index ff531ab..28d1900 100644 --- a/front/views/PlayView.tsx +++ b/front/views/PlayView.tsx @@ -3,7 +3,7 @@ import { SafeAreaView, Platform } from 'react-native'; import * as ScreenOrientation from 'expo-screen-orientation'; import { Box, Center, Column, Progress, Text, Row, View, useToast, Icon } from 'native-base'; import IconButton from '../components/IconButton'; -import { Ionicons } from "@expo/vector-icons"; +import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons"; import { useNavigation } from '@react-navigation/native'; import { useQuery, useQueryClient } from 'react-query'; import API from '../API'; @@ -13,6 +13,8 @@ import { useStopwatch } from 'react-timer-hook'; import SlideView from '../components/PartitionVisualizer/SlideView'; import MidiPlayer from 'midi-player-js'; import SoundFont from 'soundfont-player'; +import VirtualPiano from '../components/VirtualPiano/VirtualPiano'; +import { strToKey, keyToStr, Note } from '../models/Piano'; type PlayViewProps = { songId: number @@ -40,6 +42,7 @@ const PlayView = () => { const timer = useStopwatch({ autoStart: false }); const [paused, setPause] = useState(true); const [midiPlayer, setMidiPlayer] = useState(); + const [isVirtualPianoVisible, setVirtualPianoVisible] = useState(false); const partitionRessources = useQuery(["partition", songId], () => API.getPartitionRessources(songId) @@ -153,6 +156,41 @@ const PlayView = () => { + + {isVirtualPianoVisible && + { + console.log("On note down", keyToStr(note)); + }} + onNoteUp={(note: any) => { + console.log("On note up", keyToStr(note)); + }} + showOctaveNumbers={true} + startNote={Note.C} + endNote={Note.B} + startOctave={2} + endOctave={5} + style={{ + width: '80%', + height: '100%', + }} + highlightedNotes={ + [ + { key: strToKey("D3") }, + { key: strToKey("A#"), bgColor: "#00FF00" }, + ] + } + + /> + } @@ -175,6 +213,12 @@ const PlayView = () => { onPause(); } }}/> + { + setVirtualPianoVisible(!isVirtualPianoVisible); + }}/> {timer.minutes}:{timer.seconds.toString().padStart(2, '0')}