VoiceEntryInteractionListener.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { IUserDisplayInteractionListener } from "../Common/Interfaces/IUserDisplayInteractionListener";
  2. import { PointF2D, Fraction } from "../Common/DataObjects";
  3. import { InteractionType } from "../Common/Enums/InteractionType";
  4. import { GraphicalVoiceEntry } from "../MusicalScore/Graphical";
  5. import { SheetRenderingManager } from "./SheetRenderingManager";
  6. export class VoiceEntryInteractionListener implements IUserDisplayInteractionListener {
  7. private renderingManager: SheetRenderingManager;
  8. constructor(renderingManager: SheetRenderingManager) {
  9. this.renderingManager = renderingManager;
  10. }
  11. userDisplayInteraction(relativePosition: PointF2D, positionInSheetUnits: PointF2D, type: InteractionType): void {
  12. switch (type) {
  13. case InteractionType.TouchDown:
  14. case InteractionType.SingleTouch:
  15. case InteractionType.DoubleTouch: {
  16. const clickVe: GraphicalVoiceEntry = this.renderingManager.GraphicalMusicSheet.GetNearestVoiceEntry(
  17. positionInSheetUnits,
  18. );
  19. // set cursor and/or start/end marker position
  20. if (clickVe) {
  21. if (clickVe.parentStaffEntry.parentVerticalContainer !== undefined) {
  22. const clickedTimeStamp: Fraction = clickVe.parentStaffEntry.parentVerticalContainer.AbsoluteTimestamp;
  23. this.renderingManager.setStartPosition(clickedTimeStamp);
  24. // playback clicked note
  25. if (clickVe.notes[0]?.sourceNote.Pitch !== undefined) {
  26. this.renderingManager.PlaybackManager?.playVoiceEntry(clickVe.parentVoiceEntry);
  27. }
  28. }
  29. }
  30. break;
  31. }
  32. default:
  33. // Do nothing
  34. break;
  35. }
  36. }
  37. }