Skip to content

Commit c6b071f

Browse files
committed
Stop/start
1 parent e803cf1 commit c6b071f

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/components/StepInput.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/* components/StepInput.css */
22

3-
.step-input-button {
3+
.active {
4+
border-style: solid;
5+
background-color: red;
6+
color: white;
47
}

src/components/StepInput.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useRef } from 'react';
1+
import React, { useRef, useState } from 'react';
22

33
import './StepInput.css';
44
import { dispatchCurrentBeatEvent } from '../events/dispatchCurrentBeatEvent';
@@ -15,6 +15,7 @@ const StepInput: React.FC<StepInputProps> = ({ gridIndex }) => {
1515
const { grids, selectedInput, setOrUpdateNoteInGrid, inputChannels } = useMusicStore();
1616
const grid = grids[gridIndex];
1717
const currentBeatRef = useRef(0);
18+
const [stepInputMode, setStepInputMode] = useState(false); // State for step input mode
1819

1920
const handleMIDIMessage = (event: WebMidi.MIDIMessageEvent) => {
2021
const [status, note, velocity] = event.data;
@@ -28,13 +29,15 @@ const StepInput: React.FC<StepInputProps> = ({ gridIndex }) => {
2829
}
2930
};
3031

31-
const toggleStepInputMode = () => {
32-
if (currentBeatRef.current > 0) {
32+
const toggleStepInputMode = (forceStop: boolean = false) => {
33+
if (stepInputMode || forceStop) {
3334
// Reset current beat when exiting step input mode
3435
currentBeatRef.current = 0;
3536
stopListening();
37+
setStepInputMode(false); // Update state
3638
} else {
3739
startListening();
40+
setStepInputMode(true); // Update state
3841
}
3942
};
4043

@@ -68,22 +71,23 @@ const StepInput: React.FC<StepInputProps> = ({ gridIndex }) => {
6871
const nextBeat = currentBeatRef.current + 1;
6972

7073
// Check if the next beat exceeds the number of columns
74+
console.log(nextBeat, grid.numColumns)
7175
if (nextBeat >= grid.numColumns) {
72-
toggleStepInputMode(); // Automatically stop if out of bounds
76+
toggleStepInputMode(true); // Automatically stop if out of bounds
7377
currentBeatRef.current = 0; // Reset current beat for the next activation
74-
}
75-
else {
78+
} else {
7679
currentBeatRef.current = nextBeat; // Update the current beat
7780
dispatchCurrentBeatEvent(currentBeatRef.current);
7881
}
7982
};
8083

8184
return (
82-
<button className='step-input-button' onClick={toggleStepInputMode}
83-
title={currentBeatRef.current > 0 ? 'Exit step input mode' : 'Enter step input mode'}
85+
<button className={`step-input-button ${stepInputMode ? 'active' : ''}`}
86+
onClick={() => toggleStepInputMode()}
87+
title={stepInputMode ? 'Exit step input mode' : 'Enter step input mode'}
8488
>
85-
{currentBeatRef.current > 0 ? 'Exit' : 'Step'}
86-
</button >
89+
{stepInputMode ? 'Exit' : 'Step'}
90+
</button>
8791
);
8892
};
8993

0 commit comments

Comments
 (0)