<commit_before>import {MusicPartManagerIterator} from "../MusicalScore/MusicParts/MusicPartManagerIterator";
import {MusicPartManager} from "../MusicalScore/MusicParts/MusicPartManager";
import {VoiceEntry} from "../MusicalScore/VoiceData/VoiceEntry";
import {VexFlowStaffEntry} from "../MusicalScore/Graphical/VexFlow/VexFlowStaffEntry";
import {MusicSystem} from "../MusicalScore/Graphical/MusicSystem";
import {OSMD} from "./OSMD";
import {GraphicalMusicSheet} from "../MusicalScore/Graphical/GraphicalMusicSheet";


export class Cursor {
    constructor(container: HTMLElement, osmd: OSMD) {
        this.container = container;
        this.osmd = osmd;
        let curs: HTMLElement = document.createElement("img");
        curs.style.position = "absolute";
        curs.style.zIndex = "-1";
        this.cursorElement = <HTMLImageElement>curs;
        container.appendChild(curs);
    }

    private container: HTMLElement;
    private osmd: OSMD;
    private iterator: MusicPartManagerIterator;
    private graphic: GraphicalMusicSheet;
    private hidden: boolean = true;
    private cursorElement: HTMLImageElement;

    public init(manager: MusicPartManager, graphic: GraphicalMusicSheet): void {
        this.iterator = manager.getIterator();
        this.graphic = graphic;
        this.hidden = true;
        this.hide();
    }

    public show(): void {
        this.hidden = false;
        this.update();
        // Forcing the sheet to re-render is not necessary anymore
        //this.osmd.render();
    }

    public update(): void {
        // Should NEVER call this.osmd.render()
        if (this.hidden) {
            return;
        }
        this.graphic.Cursors.length = 0;
        let iterator: MusicPartManagerIterator = this.iterator;
        if  (iterator.EndReached || iterator.CurrentVoiceEntries === undefined) {
            return;
        }
        let x: number = 0, y: number = 0, height: number = 0;
        for (let idx: number = 0, len: number = iterator.CurrentVoiceEntries.length; idx < len; ++idx) {
            let voiceEntry: VoiceEntry = iterator.CurrentVoiceEntries[idx];
            let measureIndex: number = voiceEntry.ParentSourceStaffEntry.VerticalContainerParent.ParentMeasure.MeasureNumber;
            let staffIndex: number = voiceEntry.ParentSourceStaffEntry.ParentStaff.idInMusicSheet;
            let gse: VexFlowStaffEntry =<commit_msg>Cursor on first StaffEntry by default<commit_after>import {MusicPartManagerIterator} from "../MusicalScore/MusicParts/MusicPartManagerIterator";
import {MusicPartManager} from "../MusicalScore/MusicParts/MusicPartManager";
import {VoiceEntry} from "../MusicalScore/VoiceData/VoiceEntry";
import {VexFlowStaffEntry} from "../MusicalScore/Graphical/VexFlow/VexFlowStaffEntry";
import {MusicSystem} from "../MusicalScore/Graphical/MusicSystem";
import {OSMD} from "./OSMD";
import {GraphicalMusicSheet} from "../MusicalScore/Graphical/GraphicalMusicSheet";


export class Cursor {
    constructor(container: HTMLElement, osmd: OSMD) {
        this.container = container;
        this.osmd = osmd;
        let curs: HTMLElement = document.createElement("img");
        curs.style.position = "absolute";
        curs.style.zIndex = "-1";
        this.cursorElement = <HTMLImageElement>curs;
        container.appendChild(curs);
    }

    private container: HTMLElement;
    private osmd: OSMD;
    private iterator: MusicPartManagerIterator;
    private graphic: GraphicalMusicSheet;
    private hidden: boolean = true;
    private cursorElement: HTMLImageElement;

    public init(manager: MusicPartManager, graphic: GraphicalMusicSheet): void {
        this.iterator = manager.getIterator();
        this.iterator.moveToNext();
        this.graphic = graphic;
        this.hidden = true;
        this.hide();
    }

    public show(): void {
        this.hidden = false;
        this.update();
        // Forcing the sheet to re-render is not necessary anymore
        //this.osmd.render();
    }

    public update(): void {
        // Should NEVER call this.osmd.render()
        if (this.hidden) {
            return;
        }
        this.graphic.Cursors.length = 0;
        let iterator: MusicPartManagerIterator = this.iterator;
        if  (iterator.EndReached || iterator.CurrentVoiceEntries === undefined) {
            return;
        }
        let x: number = 0, y: number = 0, height: number = 0;
        for (let idx: number = 0, len: number = iterator.CurrentVoiceEntries.length; idx < len; ++idx) {
            let voiceEntry: VoiceEntry = iterator.CurrentVoiceEntries[idx];
            let measureIndex: number = voiceEntry.ParentSourceStaffEntry.VerticalContainerParent.ParentMeasure.MeasureNumber;
            let staffIndex: number = voiceEntry.ParentSourceStaffEntry.ParentStaff.idInMusicSheet;
            let gse: VexFlowStaffEntry =
{'fraction_non_alphanumeric': 0.10664191419141915, 'fraction_numerical': 0.0024752475247524753, 'mean_word_length': 3.0173985086992543, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7442893', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1300, 'n_words': 316}