Skip to content

Commit

Permalink
#12 Prevent measure overlap of sections
Browse files Browse the repository at this point in the history
  • Loading branch information
tscz committed Jan 18, 2020
1 parent 5c3f84a commit ab3980e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
11 changes: 7 additions & 4 deletions src/components/audioManagement/audioManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ class AudioManagement extends React.Component<AllProps> {
this.repaintWaveform(
this.props.sections,
this.props.measures,
this.props.zoomLevel
this.props.zoomLevel,
this.props.secondsPerMeasure
);
}

Expand All @@ -125,7 +126,8 @@ class AudioManagement extends React.Component<AllProps> {
this.repaintWaveform(
this.props.sections,
this.props.measures,
this.props.zoomLevel
this.props.zoomLevel,
this.props.secondsPerMeasure
);
}

Expand Down Expand Up @@ -165,11 +167,12 @@ class AudioManagement extends React.Component<AllProps> {
private repaintWaveform(
sections: NormalizedObjects<Section>,
measures: NormalizedObjects<Measure>,
zoomLevel: number
zoomLevel: number,
timePerMeasure: number
) {
this.getPeaks()?.segments.removeAll();
this.getPeaks()?.segments.add(
PeaksConfig.sectionsToSegment(sections, measures)
PeaksConfig.sectionsToSegment(sections, measures, timePerMeasure)
);
this.getPeaks()?.points.removeAll();
this.getPeaks()?.points.add(PeaksConfig.measuresToPoints(measures));
Expand Down
11 changes: 7 additions & 4 deletions src/components/audioManagement/peaksConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,21 @@ class PeaksConfig {

static sectionsToSegment = (
sections: NormalizedObjects<Section>,
measures: NormalizedObjects<Measure>
measures: NormalizedObjects<Measure>,
timePerMeasure: number
) => {
let segments: SegmentAddOptions[] = [];
sections.allIds.forEach(id => {
const section = sections.byId[id];

const start = measures.byId[section.measures[0]].time;
const end = start + timePerMeasure;

let segment: SegmentAddOptions = {
id,
labelText: section.type,
startTime: measures.byId[section.measures[0]].time,
endTime:
measures.byId[section.measures[section.measures.length - 1]].time,
startTime: start,
endTime: end,
color: PeaksConfig.SECTIONTYPE_TO_COLOR.get(section.type),
editable: false
};
Expand Down
2 changes: 1 addition & 1 deletion src/states/analysis/analysisSlice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ it("can remove sections after changing rhythm", () => {

expect(state.sections.allIds.length).toBe(2);
expect(state.sections.byId["BRIDGE_0_98"]).toBeDefined();
expect(state.sections.byId["UNDEFINED_98_99"]).toBeDefined();
expect(state.sections.byId["UNDEFINED_99_99"]).toBeDefined();

state = reducer(state, updatedRhythm({ bpm: 60 }));

Expand Down
6 changes: 3 additions & 3 deletions src/states/analysis/analysisUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const undefinedSection = (length: number) => {

export const sectionInvalid = (section: Section) => {
return (
parseInt(section.measures[0]) >=
parseInt(section.measures[0]) >
parseInt(section.measures[section.measures.length - 1])
);
};
Expand Down Expand Up @@ -82,7 +82,7 @@ export const mergeSections: (
//Add a new undefined block before the new section
if (newSectionStart > currentSectionStart) {
let section: Section = {
measures: ArrayUtil.range(currentSectionStart, newSectionStart),
measures: ArrayUtil.range(currentSectionStart, newSectionStart - 1),
type: SectionType.UNDEFINED
};
newSections.push(section);
Expand All @@ -94,7 +94,7 @@ export const mergeSections: (
//Add a new undefined block after the new section
if (newSectionEnd < currentSectionEnd) {
let section: Section = {
measures: ArrayUtil.range(newSectionEnd, currentSectionEnd),
measures: ArrayUtil.range(newSectionEnd + 1, currentSectionEnd),
type: SectionType.UNDEFINED
};
newSections.push(section);
Expand Down

0 comments on commit ab3980e

Please sign in to comment.