Skip to content

add timebase master example - #19

Closed
Vampouille wants to merge 4 commits into
spatialaudio:masterfrom
Vampouille:timebase_example
Closed

Vampouille wants to merge 4 commits into
spatialaudio:masterfrom
Vampouille:timebase_example

Conversation

@Vampouille

Copy link
Copy Markdown
Contributor

No description provided.

@mgeier

mgeier commented Jun 5, 2015

Copy link
Copy Markdown
Member

That's great, thank you!

I think this helps a lot to understand how the timebase callback is supposed to work.

Just for reference, there is a similar example in the JACK sources:
https://github.com/jackaudio/example-clients/blob/master/intime.c

The code is still quite simple, so we can probably add a few more features ...?

What about passing the values (BPM etc.) as (optional) command line arguments?
See https://github.com/spatialaudio/jackclient-python/blob/master/examples/thru_client.py for how to do that.

What about user input during runtime?

Since we already use input(), we might as well use it for user input ...
The user could e.g. change the BPM by pressing 120<Return> and quit the program by pressing q<Return>.
Or would this be too much?

@Vampouille

Copy link
Copy Markdown
Contributor Author

not too much, it would be great !

Comment thread examples/timebase_master.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should check new_pos, right?

You should also change nframes to blocksize (and you will actually need it in the implementation).

See https://github.com/jackaudio/example-clients/blob/master/intime.c.

@Vampouille

Copy link
Copy Markdown
Contributor Author

I'm not agree with else part of intime.c (if new_pos). In my app, I never check new_pos, I always compute bar, beat, ticks from frame position, fps and bpm. I don't increment ticks based on blocksize. Maybe this part of code is faster .... but this "else" does not add any feature !

About new_pos parameter, I can print something when new_pos is True like 'Transport moved' or 'New Position'

About frames2ticks() function, yes I will 'inline' it

@Vampouille

Copy link
Copy Markdown
Contributor Author

bbt_offset field is missing maybe in future version. This is not implemented in ardour, hydrogen or qtractor but it is a must have in order to handle bpm modification in a song (from bar 90, bpm change from 120 to 135)

@mgeier

mgeier commented Jun 9, 2015

Copy link
Copy Markdown
Member

Thanks for the changes, the new features are great!

I still don't quite understand how the new_pos parameter should be handled.
The documentation for JackTimebaseCallback states:

pos: address of the position structure for the next cycle; pos->frame will be its frame number. If new_pos is FALSE, this structure contains extended position information from the current cycle. If TRUE, it contains whatever was set by the requester. The timebase_callback's task is to update the extended information here.

So in the case of new_pos being False, shouldn't most of the fields already contain the right information?
Why are you re-assigning most of the values?
Is this necessary?

The docs say

... If TRUE, it contains whatever was set by the requester ...

They also speak about jack_transport_reposition() and jack_transport_locate() ... could a different client request, say, a different BPM value or different beats_per_bar?

Wouldn't you have to check for pos.valid in case of new_pos being True?

Sorry for the dumb questions, I'm just trying to understand ...

@Vampouille

Copy link
Copy Markdown
Contributor Author

At the beginning of callback pos struct have previous value. For example pos.tick was set to 43 and, after calculation, callback set pos.tick to 56.
If new_pos is False then we are sure that pos contains previous transport position. But we cannot use those information to compute new position because ticks are rounded. With bbt_offset and bar, beat, tick we can recompute position.

@mgeier

mgeier commented Jun 12, 2015

Copy link
Copy Markdown
Member

I see, thanks for the clarification:

I still don't understand this: what happens if a different client uses jack_transport_reposition()?
Wouldn't this be ignored in your current implementation?

@Vampouille

Copy link
Copy Markdown
Contributor Author

Yes, like other soft like Qtractor. My first try was to use jack_transport_reposition() to change bpm but other jack client overwrite this value, so I set timebase master.

@mgeier

mgeier commented Jun 15, 2015

Copy link
Copy Markdown
Member

OK, so if another client uses jack_transport_locate() it works and if it uses jack_transport_reposition() the request is ignored.

Is this correct?

If yes, I think it would be good to issue a notification message in the example client if a different client sets some data which is ignored.

@Vampouille

Copy link
Copy Markdown
Contributor Author

yes, it is correct.

In example, I can check beat_per_minute fields. If new_pos is False and user does not supply new value, pos.bpm should already have good value. I can also check ticks_per_beat, beat_per_bar, ... but I cannot check bbt fields beacause ticks are rounded.

@mgeier

mgeier commented Jun 15, 2015

Copy link
Copy Markdown
Member

OK. I think it would be good if you could ...

  • only assign values where it's actually necessary
  • use all provided values as long as it makes sense and it's not too complicated
  • for all other values (which are currently ignored), print an information message

@Vampouille

Copy link
Copy Markdown
Contributor Author

I changed example, now, bpm and others static fields : bar_start_tick, beats_per_bar, .... are overwrite only when new_pos is True. If new_pos is False I test if those fields are modified.

I test with ardour and qtractor, it seems that when you jump in song those application or jack reset pos struct to a fresh new memory emplacement with strange value :

'bar start tick' modified by another app 0.0 -> 1e-323
'beats per bar' modified by another app 4.0 -> 0.0
'beat type' modified by another app 4.0 -> 5.324934164434305e-44
'ticks per beat' modified by another app 960.0 -> 2.81713227e-316
'beats per minute' modified by another app or user 130 -> 0.0

state value is still 1 (playing) pos.frame is set to zero only by qtractor which produce a division by zero. Ardour set ticks per beat very low so it is rounded to zero too.

With previous version, I still have division by zero with qtractor just with a mouse click on tempo spin box to set focus on it.

I find nothing on internet about frame rate set to zero.

@mgeier

mgeier commented Jun 22, 2015

Copy link
Copy Markdown
Member

Thanks for your changes.

But now it doesn't seem to work anymore ...

... are overwrite only when new_pos is True.

But aren't you supposed to check the values in this case?

I think you should check pos.valid, right?

It's very strange that the frame_rate is zero, especially since the docs state: "these cannot be set from clients; the server sets them".

@Vampouille

Copy link
Copy Markdown
Contributor Author

I reorganize callback, now I check about modified fields only when pos.valid have BBT flag set. I always set pos fields.
I think the good question is how to test this ? I think we need an external software like qtractor or ardour that use transport_reposition() function....

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should check this only if new_pos is true.
If not, I guess we should assume all fields except the first 3 contain whatever we assigned before, right?

@mgeier

mgeier commented Jun 30, 2015

Copy link
Copy Markdown
Member

how to test this ?

That's indeed a good question!

I think we need an external software like qtractor or ardour that use transport_reposition() function....

But do they respect if another client wants to be timebase master?
I guess they are typically timebase masters themselves, right?

Would #22 help?

@mgeier

mgeier commented Aug 18, 2015

Copy link
Copy Markdown
Member

I merged #22 into master.

@mgeier

mgeier commented Oct 15, 2016

Copy link
Copy Markdown
Member

@Vampouille If you are still interested in this, I've just added an implementation of the "showtime" client, see #20.

@Vampouille

Copy link
Copy Markdown
Contributor Author

For me, the purpose of this PR is to show an example of computation of bar, beat and ticks from pos.frame. Interaction with other tools are maybe out of scope of this example. "Showtime" client may help in understanding interaction. So maybe we can add some comments in this example to explain limitation.

@mgeier

mgeier commented Oct 24, 2016

Copy link
Copy Markdown
Member

Interaction with other tools are maybe out of scope of this example.

I think we shouldn't ignore other tools. Especially with the handling of new_pos, see my comment above: #19 (comment).
I think new_pos can only be understood if there is another client interacting, right?
Or probably it can be the same client making those changes ... but then we would need an extended user interface that allows such changes in addition to changing the BPM.

What about my other questions/comments?

It would be nice to get this example into master, but I think a few things should be changed before.

@Vampouille

Copy link
Copy Markdown
Contributor Author

Thanks @mgeier !

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

Successfully merging this pull request may close these issues.

2 participants