No internet connection
  1. Home
  2. How to

Read current timecode position in Pro Tools and send to a browser to create an scrollable script that follows the playhead cursor

By Stefan Möhl @Stefan_Mohl
    2020-04-28 07:35:49.997Z2020-04-28 08:18:58.361Z

    I want to use Soundflow as a tool to read (if ProTools is running) the timecode via MTC and then use this timecode information stored in a variable to send to a script e.g. a docx and scroll into the specific passage of the script.
    I saw that Google Chrome is able to read MTC.
    So my idea is that I load the script into Chrome Browser and let it follow the cursor position of Pro Tools as an "autoscroller".
    Or perhaps I could send the timecode information directly to Microsoft Word with a Word API. I don´t know if this is possible.
    Has anyone experience with that?
    In SF I have seen that it is possible to read the Main Counter so this is already very good to start.

    The script contains 3 columns.
    Timecode information mm:ss | Role | Text

    So my first attempt to get TC information works quiet good.

    var lastIsPlayingValue;
    
    function main() {
        var isPlaying = sf.ui.proTools.isPlaying;
        if (isPlaying === lastIsPlayingValue) 
            return;
        lastIsPlayingValue = isPlaying;
    
        if (!isPlaying) {
            //Insert your code to run here
            log('Pro Tools stopped');
            // exit loop How???
            
        }
    }
    
    function runForever(name, action, interval, timeout) {
        var now = (new Date).valueOf();
        if (now - globalState[name] < timeout) throw 0; //Exit if we were invoked again inside the timeout
    
        globalState[name] = now;
        sf.engine.runInBackground(function () {
            try {
                while (true) {
                    sf.engine.checkForCancellation();
                    globalState[name] = (new Date).valueOf();
    
                    action();
                    var currentTimecode = sf.ui.proTools.mainWindow.counterDisplay.mainCounter.value.invalidate().value;
                    
                    var currentTimecodeAsText = currentTimecode.substr(3,5);
                    log(currentTimecodeAsText);
                    sf.clipboard.setText({text: currentTimecodeAsText})
                    
    
                    sf.wait({ intervalMs: interval, executionMode: 'Background' });
                }
            } finally {
                globalState[name] = null;
            }
        });
    

    I think the next step is to convert my docx file into a file readable by Google Chrome browser. Is this possible inside Soundflow?
    Can someone help me out with some tips.

    Stefan

    • 14 replies

    There are 14 replies. Estimated reading time: 11 minutes

    1. Hi Stefan.
      Thank you for taking this question to the forum :)

      SoundFlow does have an internal MTC reader, but - it's actually often better to read the timecode information directly from the main counter display continually.

      The three things you need to combine for your script are:

      • Read the current timecode:
      sf.ui.proTools.mainWindow.counterDisplay.mainCounter.value.invalidate().value
      
      • Use a runForever script to keep your script running all the time
        See here for an example: https://forum.soundflow.org/-989#post-7
      • Apply the scrolling in your Word document. I'm less sure how you would implement this scrolling in Word.
      1. Instead of rolling this quite complex script on your own, you might be interested in an app we'll be developing for SoundFlow which would take care of providing scrolling Notes based on where you are in your timeline.

        1. Stefan Möhl @Stefan_Mohl
            2021-03-08 22:16:47.012Z

            Hi Christian,

            I'll pick up the thread again and think it will be easiest to develop an app within Soundflow which emulates the behavior of a teleprompter and depending on its position in the timeline in ProTools allows the text to scroll along.
            In the best case, this will be a small text editor in which you can also search for text passages or timecodes and then let ProTools jump to the corresponding position.

            I need some start-up help with my project.
            Is it possible to read a word document into a table in a surface?
            I could not figure out how to add data to the table.

            Can the timecode from ProTools be written into a table?

            I appreciate any help.
            Stefan

            1. Hi Stefan

              Using dynamic data in tables is currently only possible for registered SoundFlow Developers who have gone through our internal training program (we're running the first round of classes right now).
              Would you want me to pass this idea on to our current developer group to see if any of them would be interested in implementing something like this?

              1. If you're interested in joining the developer program yourself and you have sufficient knowledge of javascript and regular SF scripting, please contact us on help@soundflow.org to get on the list of candidates for our 2nd round of the Developer Program starting later this year :)

                1. In reply tochrscheuer:
                  Stefan Möhl @Stefan_Mohl
                    2021-03-08 22:50:15.902Z

                    Hi Christian,

                    that would be great. Yes I would like to join
                    Thank you.

                    Stefan

                    1. In reply tochrscheuer:
                      Stefan Möhl @Stefan_Mohl
                        2021-03-08 22:52:36.803Z

                        Hi Christian,
                        if you could pass the idea in the developers group that would be nice.
                        Stefan

                        1. Will do! Thank you :)

                2. In reply toStefan_Mohl:

                  Hi Stefan.

                  I see you edited your question. I am not 100% sure I follow your logic, but it looks like you're aiming to be running SoundFlow Javascript code directly in Chrome. This is not possible.
                  SoundFlow's Javascript engine gives you access to SoundFlow's internal functionality, which includes the Pro Tools integrations, UI integrations, etc. etc. By just running regular Javascript inside Chrome, you don't have access to all this.

                  I would instead architect it like this:

                  • In Chrome, load a scrollable version of your document. Write a websocket server, that can receive timecode events in a format you design, for example it could be just a string representing the current timecode. Upon receiving a timecode event, do the math to scroll to the right position within your document.
                  • Inside SF, use your runForever script that constantly reads the current Pro Tools timecode and forwards this information to the websocket server you opened up in Google Chrome.
                  1. Stefan Möhl @Stefan_Mohl
                      2020-04-28 13:44:02.254Z

                      Hi Christian,

                      that sounds like a great plan for a nice project.
                      I hope I can put all your suggestions together but I am very exited.
                      The main part took place outside the SF environement I guess.
                      Are there any documentation how to send data via sockets in Soundflow?

                      Best Stefan

                      1. Currently, we don't have any documentation on using WebSockets from SoundFlow no, but you can see an example here:
                        https://forum.soundflow.org/-1842

                        1. Stefan Möhl @Stefan_Mohl
                            2020-04-29 14:40:47.971Z

                            I have an approach that seems to be a good way to go.
                            The manuscript in docx format has the following table structure:
                            ––––––––––––––––––––––
                            | mm:ss | role | text to record |
                            ––––––––––––––––––––––
                            | 00:13 | JIM | This is a great idea.
                            | 00:19 | ANN | Yes. It is.

                            I converted the docx file into a simple html structure and added hyperlink using the id of the link target, preceded by # for each second. This way I can jump to timecode 00:13 in the script with a link that e.g. looks like this:
                            file:///Users/stefanmoehl/Desktop/TCReader/out.html#13
                            where 13 represents the TC of the ProTools cursor.

                            Here is the basic structure of the html presentation

                            
                            <div id="13"></div>
                            <p>00:13</p>
                            <p >JIM</p>
                            <p >This is a great idea.</p>
                            
                            <div id="14"></div>
                            <div id="15"></div>
                            <div id="16"></div>
                            <div id="17"></div>
                            <div id="18"></div>
                            <div id="19"></div>
                            
                            <p>00:19</p>
                            <p >ANN</p>
                            <p >Yes. It is.</p>
                            

                            I have started a script in SF that create s the link.

                            var hours = 0;
                            var minutes = 0;
                            var seconds = 0;
                            var secondsInTotal = 0;
                            
                            function createLinkWithTimecode() {
                                var hours = 0;
                                var minutes = 0;
                                var seconds = 0;
                                var secondsInTotal = 0;
                                var link = '';
                            
                            
                            
                                var currentTimecode = sf.ui.proTools.mainWindow.counterDisplay.mainCounter.value.invalidate().value;
                                hours =  parseInt( currentTimecode.substr(0,2) );
                                if (hours == 10)
                                    hours = 0;
                                if (hours == 11)
                                    hours = 1;
                                minutes = parseInt( currentTimecode.substr(3,2) );
                                seconds =  parseInt( currentTimecode.substr(6,2) );
                                secondsInTotal = hours*3600 + minutes*60 + seconds;
                                log('hours: '+ hours.toString() + ' minutes: ' + minutes.toString() + ' seconds: ' + seconds.toString() + ' secondsInTotal: ' + secondsInTotal.toString());
                                link = 'file:///Users/stefanmoehl/Desktop/TCReader/out.html#' + secondsInTotal;
                                log(link);
                                sf.clipboard.setText({text: link})
                                // send this link to the browser each second? 
                            
                                sf.file.open({
                                    path: link,
                                    applicationPath: "/Applications/Firefox.app",
                                });
                            
                            };
                            
                            
                            createLinkWithTimecode();
                            

                            the creation of the link is working.
                            I want to test it by running it inside from SF with the sf.file.open function but that does not work as it should as it cuts the anchor at the end of the url.
                            It should open file:///Users/stefanmoehl/Desktop/TCReader/out.html#934
                            but it opens only file:///Users/stefanmoehl/Desktop/TCReader/out.html

                            Do you know why the open function cuts the url?

                            Of course this is just for testing.
                            The next step is to create the server model to receive the TC from the website.

                            1. Great progress!

                              I would test this by finding out how you can open Firefox or Chrome from Terminal where the anchor follows along. Likely something like just:

                              open "file:///Users/stefanmoehl/Desktop/TCReader/out.html#934"
                              

                              If that works, you just do this in SF:

                              sf.system.exec({ commandLine: `open "file:///Users/stefanmoehl/Desktop/TCReader/out.html#934"` });
                              
                      2. In reply toStefan_Mohl:
                        Stefan Möhl @Stefan_Mohl
                          2020-04-29 23:17:15.384Z

                          That will do it. Thanks.

                          sf.system.exec({ commandLine: `/Applications/Firefox.app/Contents/MacOS/firefox --new-tab https://soundflow.org` });