Skip to content

Commit

Permalink
Added selecting of cue markers and textfield for position in properti…
Browse files Browse the repository at this point in the history
…es panel
  • Loading branch information
ArthurHeitmann committed Feb 16, 2024
1 parent 5095d2c commit 271aa25
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 32 deletions.
12 changes: 10 additions & 2 deletions lib/stateManagement/openFiles/types/BnkFilePlaylistData.dart
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,17 @@ class BnkTrackData with HasUuid, Undoable implements Disposable {
}
}
enum BnkMarkerRole {
entryCue, exitCue, custom
entryCue("Entry"), exitCue("Exit"), custom("Custom");

final String name;

const BnkMarkerRole(this.name);
}
class BnkSegmentMarker with HasUuid, Undoable implements Disposable {
final OpenFileId file;
final BnkMusicMarker srcMarker;
final NumberProp pos;
late final XmlProp posSelectable;
final BnkMarkerRole role;
String get name => srcMarker.pMarkerName ?? "";
BnkSegmentMarker(this.file, this.srcMarker, this.pos, this.role) {
Expand All @@ -450,14 +455,17 @@ class BnkSegmentMarker with HasUuid, Undoable implements Disposable {

void _setupListeners() {
pos.addListener(_onPropChanged);
posSelectable = XmlProp(file: file, tagId: 0, tagName: "${role.name} cue marker", parentTags: [], children: [
XmlProp(file: file, tagId: 0, tagName: "time", value: pos, parentTags: [])
]);
}
void _onPropChanged() {
areasManager.fromId(file)!.setHasUnsavedChanges(true);
}

@override
void dispose() {
pos.dispose();
posSelectable.dispose();
}

void applyTo(BnkMusicMarker newMarker) {
Expand Down
72 changes: 42 additions & 30 deletions lib/widgets/filesView/types/bnkPlaylistEditor/BnkSegmentEditor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import '../../../../stateManagement/openFiles/types/BnkFilePlaylistData.dart';
import '../../../../utils/utils.dart';
import '../../../misc/ChangeNotifierWidget.dart';
import '../../../misc/CustomIcons.dart';
import '../../../misc/Selectable.dart';
import '../../../theme/customTheme.dart';
import 'BnkPlaylistEditorInheritedData.dart';
import 'BnkTrackEditor.dart';
Expand Down Expand Up @@ -104,53 +105,64 @@ class _BnkSegmentEditorState extends ChangeNotifierState<BnkSegmentEditor> {
}

List<Widget> getMarkers(BuildContext context, AudioEditorData viewData) {
return [
for (var i = 0; i < widget.segment.markers.length; i++) ...[
Positioned(
left: widget.segment.markers[i].pos.value / viewData.msPerPix.value + viewData.xOff.value + getMarkerOffset(widget.segment.markers[i].role),
width: BnkSegmentEditor.markerSize,
// move down a bit, by how close this marker is to the previous one
top: i - 1 >= 0
? clamp(10.0 - (widget.segment.markers[i].pos.value - widget.segment.markers[i - 1].pos.value).abs() / viewData.msPerPix.value, 0, 10)
: 0,
child: GestureDetector(
onHorizontalDragUpdate: (_) {
var pos = widget.segment.markers[i].pos;
var newPos = getMousePosOnTrack(viewData.xOff, viewData.msPerPix, context);
newPos = SnapPointsData.of(context).trySnapTo(newPos, [pos], viewData.msPerPix.value);
pos.value = newPos;
AudioPlaybackScope.of(context).cancelCurrentPlayback();
},
child: Icon(
getMarkerIcon(widget.segment.markers[i].role),
size: BnkSegmentEditor.markerSize,
color: getMarkerColor(context, widget.segment.markers[i].role)
),
),
List<Widget> widgets = [];
for (var (i, marker) in widget.segment.markers.indexed) {
widgets.add(
ChangeNotifierBuilder(
notifier: selectable.active,
builder: (_) {
var markerSize = BnkSegmentEditor.markerSize * (selectable.isSelected(marker.posSelectable.uuid) ? 1.25 : 1);
return Positioned(
left: marker.pos.value / viewData.msPerPix.value + viewData.xOff.value + getMarkerOffset(marker.role, markerSize),
width: markerSize,
// move down a bit, by how close this marker is to the previous one
top: i - 1 >= 0
? clamp(10.0 - (marker.pos.value - widget.segment.markers[i - 1].pos.value).abs() / viewData.msPerPix.value, 0, 10)
: 0,
child: GestureDetector(
onHorizontalDragUpdate: (_) {
var pos = marker.pos;
var newPos = getMousePosOnTrack(viewData.xOff, viewData.msPerPix, context);
newPos = SnapPointsData.of(context).trySnapTo(newPos, [pos], viewData.msPerPix.value);
pos.value = newPos;
AudioPlaybackScope.of(context).cancelCurrentPlayback();
},
onTap: () => selectable.select(widget.segment.file, marker.posSelectable),
child: Icon(
getMarkerIcon(marker.role),
size: markerSize,
color: getMarkerColor(context, marker.role)
)
),
);
}
),
);
widgets.add(
Positioned(
left: widget.segment.markers[i].pos.value / viewData.msPerPix.value + viewData.xOff.value,
left: marker.pos.value / viewData.msPerPix.value + viewData.xOff.value,
width: 2,
top: BnkSegmentEditor.headerHeight / 2,
bottom: 0,
child: IgnorePointer(
child: Container(
color: getMarkerColor(context, widget.segment.markers[i].role),
color: getMarkerColor(context, marker.role),
),
),
),
]
];
);
}
return widgets;
}

double getMarkerOffset(BnkMarkerRole type) {
double getMarkerOffset(BnkMarkerRole type, double markerSize) {
switch (type) {
case BnkMarkerRole.entryCue:
return -3;
case BnkMarkerRole.exitCue:
return -BnkSegmentEditor.markerSize + 4;
return -markerSize + 4;
default:
return -BnkSegmentEditor.markerSize / 2;
return -markerSize / 2;
}
}

Expand Down

0 comments on commit 271aa25

Please sign in to comment.