JSON Edit Modes === ## Table of Contents [TOC] ## Overview The Vb tool uses two main things, JSON file (contains visuals raw data) and audio files (for all recording periods with format m4a), the structure of JSON file contains multiple periods with types, "recording" or "pause". Each recording period related to an audio file. This tool used for 2 main functions: * Replace Audio File * Delete Audio File ### Replace Audio File This feature is needed whenever the developer needs to update any audio file. Updating an audio file changes the length of the recording period audio and the total audio length of the video so we need to update the JSON file to cope with changes in audio. The changes in the JSON file happens in two phases: * Interpolation get the change in scale between the new period length to the original period length $$ change ratio = \frac{NewPeriodEndtime - NewPeriodStarttime}{OldPeriodEndtime - OldPeriodStarttime} $$ Then after we get change ratio we try to scale three things in the changed period : * End period time * Actions start times and actions end times * point "t" times * Shifting Get the shift between the old end new period time and the end of the original period time $$ shift = NewPeriodEndtime - OldPeriodEndtime $$ Then we add this shift to three things on each period: * Start period time and end period time * Action start time and action end time * Point "t" time ### Delete Audio File If you want to delete an audio file in a specific period, the deleted period in JSON file will be therefore changed to pause period and we'll combine it to (before and/or after) pause periods. We do the delete process in several steps: * Get the length of the period with deleted audio * Get the start_time of this period * Change this 3 things in that period each * Change action start time and action end time to start_time * Each time t in points to start_time * Delete period endTime key * Change type to pause period * Change each period after the period with deleted audio by subtracting the shift from each : * Start time and end time of each period * Action start time and action end time * Each time t in points * Check if the period before the period with deleted audio is pause then do the following steps * Combine the actions * Delete one of the periods * Change period id by subtracting one * Do the above step with the pause period after the period with deleted audio ## How to Run the Code When you want to replace an audio file in a specific period you should run the script like that: ![image](https://drive.google.com/uc?export=view&id=137mYWzVZVfbHZmWDKoLGDczPDC13vMca) When you want to delete an audio file in a specific period you should run the script like that: ![image](https://drive.google.com/uc?export=view&id=1CqnVz3eLg069nIAquoTOQuS_MvYUEBwU) You will find more Examples on this path: "smb://guest@gen-up-stor/temp/Ahmed Elsagher/Json/" ## To-Do * Try to write the scripts into OOP way * Combine the two scripts into one script