当前位置: 首页>>代码示例>>C++>>正文


C++ Transport::position方法代码示例

本文整理汇总了C++中Transport::position方法的典型用法代码示例。如果您正苦于以下问题:C++ Transport::position方法的具体用法?C++ Transport::position怎么用?C++ Transport::position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Transport的用法示例。


在下文中一共展示了Transport::position方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: execute

void PlayerLoopCommand::execute(const Transport& transport) {
  Player * p = player();
  BeatBuffer * beat_buff = p->beat_buffer();
  AudioBuffer * audio = p->audio_buffer();
  if (!audio)
    return;

  if (p->looping() && mStartFrame < 0 && mEndFrame < 0) {
    switch (mResizePolicy) {
      case RESIZE_FROM_FRONT:
        mStartFrame = p->loop_start_frame();
        break;
      case RESIZE_FROM_BACK:
        mEndFrame = p->loop_end_frame();
        break;
      case RESIZE_AT_POSITION:
      default:
        //do nothing as this is the default when nothing is set
        break;
    }
  }

  int old_loop_frames = 0;
  if (p->looping())
    old_loop_frames = p->loop_end_frame() - p->loop_start_frame();
  const unsigned int beat = beat_buff ? beat_index(beat_buff, p->frame()) : 0;

  if (mEndFrame < 0) {
    if (!beat_buff)
      return;
    unsigned int beat_end = 0;
    if (mStartFrame < 0) {
      //find both start and end frame based on current location
      //we don't use the closest index, we use the last index before our frame so we stay in the current beat
      beat_end = beat + mBeats;
      if (beat_end >= beat_buff->size())
        return;

      mStartFrame = beat_buff->at(beat);
      if (beat == beat_end)
        mEndFrame = mStartFrame;
      else
        mEndFrame = beat_buff->at(beat_end);
    } else {
      beat_end = beat_index(beat_buff, mStartFrame) + mBeats;
      mEndFrame = beat_buff->at(beat_end);
    }

    //deal with fractional part
    double remainder = fmod(mBeats, 1.0);
    if (remainder != 0.0) {
      if (beat_end + 1 < beat_buff->size()) {
        double frames = beat_buff->at(beat_end + 1) - mEndFrame;
        mEndFrame += (frames * remainder);
      } else {
        //XXX what?
      }
    }

  } else if (mStartFrame < 0) {
    if (!beat_buff)
      return;
    unsigned int beat_end = beat_index(beat_buff, mEndFrame);
    if (beat_end < mBeats) {
      mStartFrame = 0;
    } else {
      int beat_start = beat_end - mBeats;
      mStartFrame = beat_buff->at(beat_start);
      if (beat_start >= 1) {
        //deal with fractional part
        double remainder = fmod(mBeats, 1.0);
        if (remainder != 0.0) {
          double frames = mStartFrame - beat_buff->at(beat_start - 1);
          mStartFrame -= (frames * remainder);
          if (mStartFrame < 0)
            mStartFrame = 0;
        }
      }
    }
  }

  if (mStartFrame >= mEndFrame)
    return; //XXX what to do?

  p->loop_start_frame(mStartFrame);
  p->loop_end_frame(mEndFrame);
  if (mStartLooping)
    p->loop(true);
  mLooping = p->looping();

  double loop_frames = static_cast<double>(mEndFrame - mStartFrame);
  //if we are past the end point, fold
  if (p->looping()) {
    if (p->frame() > mEndFrame) {
      int offset = round(loop_frames * floor(static_cast<double>(p->frame() - mStartFrame) / loop_frames));
      p->position_at_frame(p->frame() - offset);
    } else if (old_loop_frames > 0 && loop_frames > old_loop_frames) {
      //XXX untested, do we ever hit this?
      //if the loop grows we might need to offset to before the loop 
      if (p->syncing() && beat_buff && beat + 1 < beat_buff->size()) {
//.........这里部分代码省略.........
开发者ID:x37v,项目名称:datajockey,代码行数:101,代码来源:player.cpp


注:本文中的Transport::position方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。