-
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
14 changed files
with
554 additions
and
128 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
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
94 changes: 94 additions & 0 deletions
94
src/components/sectionOverview/sectionOverview.stories.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,94 @@ | ||
import React from "react"; | ||
import { Provider } from "react-redux"; | ||
import { createStore } from "redux"; | ||
import { composeWithDevTools } from "redux-devtools-extension"; | ||
|
||
import { SectionType, TimeSignatureType } from "../../states/analysisSlice"; | ||
import { | ||
createdProject, | ||
initializedProject, | ||
LoadingStatus, | ||
Page | ||
} from "../../states/projectSlice"; | ||
import { createRootReducer, PersistedState } from "../../states/store"; | ||
import ArrayUtil from "../../util/ArrayUtil"; | ||
import SectionOverview from "./sectionOverview"; | ||
|
||
export default { | ||
title: "Components|SectionOverview", | ||
component: SectionOverview | ||
}; | ||
|
||
export const Default = () => { | ||
let store = createStore(createRootReducer, composeWithDevTools()); | ||
|
||
let persistedState: PersistedState = { | ||
analysis: { | ||
audioDuration: 100, | ||
audioSampleRate: 44400, | ||
bpm: 120, | ||
firstMeasureStart: 0, | ||
measures: { allIds: [], byId: {} }, | ||
sections: { | ||
allIds: [ | ||
"INTRO_0_3", | ||
"VERSE_4_19", | ||
"CHORUS_20_27", | ||
"VERSE_28_43", | ||
"CHORUS_44_51", | ||
"BRIDGE_52_59", | ||
"CHORUS_60_67" | ||
], | ||
byId: { | ||
INTRO_0_3: { | ||
measures: ArrayUtil.range(0, 3), | ||
type: SectionType.INTRO | ||
}, | ||
VERSE_4_19: { | ||
measures: ArrayUtil.range(4, 19), | ||
type: SectionType.VERSE | ||
}, | ||
CHORUS_20_27: { | ||
measures: ArrayUtil.range(20, 27), | ||
type: SectionType.CHORUS | ||
}, | ||
VERSE_28_43: { | ||
measures: ArrayUtil.range(28, 43), | ||
type: SectionType.VERSE | ||
}, | ||
CHORUS_44_51: { | ||
measures: ArrayUtil.range(44, 51), | ||
type: SectionType.CHORUS | ||
}, | ||
BRIDGE_52_59: { | ||
measures: ArrayUtil.range(52, 59), | ||
type: SectionType.BRIDGE | ||
}, | ||
CHORUS_60_67: { | ||
measures: ArrayUtil.range(60, 67), | ||
type: SectionType.CHORUS | ||
} | ||
} | ||
}, | ||
timeSignature: TimeSignatureType.FOUR_FOUR | ||
}, | ||
project: { | ||
audioUrl: "", | ||
currentPage: Page.DEFAULT, | ||
status: LoadingStatus.NOT_INITIALIZED, | ||
syncFirstMeasureStart: false, | ||
title: "Testproject" | ||
} | ||
}; | ||
|
||
store.dispatch(createdProject(persistedState)); | ||
store.dispatch( | ||
initializedProject({ audioDuration: 240, audioSampleRate: 44400 }) | ||
); | ||
|
||
return ( | ||
<Provider store={store}> | ||
<SectionOverview /> | ||
</Provider> | ||
); | ||
}; |
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,8 @@ | ||
import React from "react"; | ||
|
||
import TestEnvironment from "../../tests/TestEnvironment"; | ||
import SectionOverview from "./sectionOverview"; | ||
|
||
it("renders without crashing", () => { | ||
TestEnvironment.smokeTest(<SectionOverview />); | ||
}); |
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,106 @@ | ||
import { Button, ButtonGroup, Grid, Typography } from "@material-ui/core"; | ||
import React from "react"; | ||
import { connect } from "react-redux"; | ||
|
||
import { Measure, Section } from "../../states/analysisSlice"; | ||
import { ApplicationState, NormalizedObjects } from "../../states/store"; | ||
import PeaksConfig from "../audioManagement/peaksConfig"; | ||
|
||
interface PropsFromState { | ||
sections: NormalizedObjects<Section>; | ||
measures: NormalizedObjects<Measure>; | ||
} | ||
|
||
interface PropsFromDispatch {} | ||
|
||
interface Props {} | ||
|
||
type AllProps = PropsFromState & PropsFromDispatch & Props; | ||
|
||
class SectionOverview extends React.Component<AllProps> { | ||
render() { | ||
let { sections, measures } = this.props; | ||
|
||
let generateMatrix = (arr: string[], size: number) => { | ||
var res = []; | ||
for (var i = 0; i < arr.length; i = i + size) | ||
res.push(arr.slice(i, i + size)); | ||
return res; | ||
}; | ||
|
||
return ( | ||
<> | ||
<Grid container direction="column"> | ||
{sections.allIds.map(sectionId => ( | ||
<Grid item key={sectionId}> | ||
<Grid container direction="column"> | ||
<Grid item> | ||
<Typography variant="caption"> | ||
{sections.byId[sectionId].type.toLowerCase()} | ||
</Typography> | ||
</Grid> | ||
<Grid item> | ||
<Grid | ||
container | ||
direction="column" | ||
style={{ marginBottom: "5px" }} | ||
> | ||
{generateMatrix(sections.byId[sectionId].measures, 8).map( | ||
row => ( | ||
<ButtonGroup orientation="horizontal" size="small"> | ||
{row.map(measureId => { | ||
let measure: Measure = measures.byId[measureId]; | ||
|
||
return ( | ||
<Square | ||
key={measure.id} | ||
value={measure.id!} | ||
bg={ | ||
PeaksConfig.SECTIONTYPE_TO_COLOR.get( | ||
sections.byId[sectionId].type | ||
)! | ||
} | ||
></Square> | ||
); | ||
})} | ||
</ButtonGroup> | ||
) | ||
)} | ||
</Grid> | ||
</Grid> | ||
</Grid> | ||
</Grid> | ||
))} | ||
</Grid> | ||
</> | ||
); | ||
} | ||
} | ||
|
||
class Square extends React.Component<{ | ||
value: string; | ||
bg: string; | ||
}> { | ||
render() { | ||
return ( | ||
<Button | ||
{...this.props} | ||
style={{ | ||
backgroundColor: this.props.bg | ||
}} | ||
> | ||
{this.props.value} | ||
</Button> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = ({ analysis }: ApplicationState) => { | ||
return { | ||
sections: analysis.sections, | ||
measures: analysis.measures | ||
}; | ||
}; | ||
|
||
const mapDispatchToProps = {}; | ||
export default connect(mapStateToProps, mapDispatchToProps)(SectionOverview); |
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
Oops, something went wrong.