Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to sync audio playback start with my GUI step sequencer #17

Open
jamesheston opened this issue Dec 12, 2019 · 0 comments
Open

How to sync audio playback start with my GUI step sequencer #17

jamesheston opened this issue Dec 12, 2019 · 0 comments

Comments

@jamesheston
Copy link

I'm writing a simple music tracker in Python 3 that uses Csound as its audio engine, and interacts with it through ctcsound.

My main sequencer class is SongSequencer. It has a toggle_playing method that converts the program's phrase and instrument data structures into a string in .csd format. Then I use a CsoundPerformanceThread to play the audio for that in a seperate thread. My problem is that there is delay of a second or two before Csound starts actually playing the audio back, which prevents me from syncing the current step indicator in my GUI to where the audio is in the score. Are there any callback methods I can use to sync my GUI and the audio playback?

I tried using the setRtPlayCallback method but couldn't get it to do anything.

The abbreviated code of my program looks like this:

class SongSequencer:
    def __init__(self):
        #...
        self.cs = ctcsound.Csound()
        self.pt = ctcsound.CsoundPerformanceThread( self.cs.csound() )

    def toggle_playing(self, cursor_step=0):
        if self.pt.status() != 0:
            self.pt.stop()
            self.pt.join()
            self.cs.reset()
            self.pt = ctcsound.CsoundPerformanceThread( self.cs.csound() )
            self.pt.setProcessCB(self.audio_start_cb)

        channels_phrases = [[], [], [], []]
        # Add contiguous filled phrase sequences in current channel, starting at current
        # cursor step. When I find an empty phrase sequence, exit loop
        for ch_i in range(0,4):
            for psq in self.sequence[ch_i][cursor_step:]:
                if not psq:
                    break
                channels_phrases[ch_i].append(psq.phrase.steps)

        csd = phrases_to_csd(self.instruments, channels_phrases)
        ret = self.cs.compileCsdText(csd)
        if ret == ctcsound.CSOUND_SUCCESS:
            self.cs.start()
            self.cs.setPlayOpenCallback(self.audio_start_cb)
            self.pt.play()


    def audio_start_cb(self):
        print('AUDIO PLAYING NOW')
        print('AUDIO PLAYING NOW')
        print('AUDIO PLAYING NOW')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant