[Maya C++ API] Get frame rate

I’m having a frustrating little issue trying to get the frame rate of my scene. The documentation is a little confusing since it doesn’t specify a type for the return for playbackSpeed(). Someone from Autodesk told me that it’s supposed to return an MTime. But when I try it with the code below I only get a return of 0. I’m hoping someone can help me out. Thanks!

https://help.autodesk.com/view/MAYAUL/2018/ENU/?guid=__cpp_ref_class_m_anim_control_html

MTime sceneStartFrame = MAnimControl::minTime();
MTime sceneEndFrame = MAnimControl::maxTime();
MTime frameRate = MAnimControl::playbackSpeed();

double fSceneStartFrame = (int)sceneStartFrame.as(MTime::uiUnit());
double fSceneEndFrame = (int)sceneEndFrame.as(MTime::uiUnit());
double fFrameRate = (int)frameRate.as(MTime::uiUnit());
	
MGlobal::displayInfo( "Start Frame: " );
MGlobal::displayInfo(MString() + fSceneStartFrame);
MGlobal::displayInfo( "End Frame: " );
MGlobal::displayInfo(MString() + fSceneEndFrame);
MGlobal::displayInfo( "Frame Rate: " );
MGlobal::displayInfo(MString() + fFrameRate);

seems like playbackSpeed will return this constant value, not the current framerate.

OK, it’s actually returning an index to that Playback speed attribute. So how does one get the frame rate? I don’t see that method in the docs anywhere.

The MTime static function uiUnit will return the enum associated with the time mode of the scene which essentially correlates to a frameRate.

Unfortunately I didn’t see anything that returns the frameRate in the SDK. In your shoes I would map the enum to a frameRate. Maybe its a global somewhere in a header file. Another option is to see if you can get the frameRate from ticksPerSecond()? In 3dsMax I remember having to multiply this constant by some factor that was passed by the timeMode.

…it should be simple.

Thanks for the response. I actually came across a solution, but an Autodesk tech also provided some good knowledge. Here’s the thread for posterity.

https://forums.autodesk.com/t5/maya-programming/c-get-frame-rate/td-p/7832521

I still don’t get it… where did he get the integer 24?

Or is he just pointing out that to ensure your play rate is accurate its important to incorporate the playback speed.

As I understand it, it’s the later.

Just to be clear – is the intention here to get the nominal playback speed of the scene, or the actual time it takes for maya to update the viewport?