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


C++ MID函数代码示例

本文整理汇总了C++中MID函数的典型用法代码示例。如果您正苦于以下问题:C++ MID函数的具体用法?C++ MID怎么用?C++ MID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: paCallback

//////////////////////
// PortAudio callback
int PortAudioPlayer::paCallback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, PaTimestamp outTime, void *userData) {
	// Get provider
	PortAudioPlayer *player = (PortAudioPlayer *) userData;
	AudioProvider *provider = player->GetProvider();
	int end = 0;

	// Calculate how much left
	__int64 lenAvailable = player->endPos - player->playPos;
	uint64_t avail = 0;
	if (lenAvailable > 0) {
		avail = lenAvailable;
		if (avail > framesPerBuffer) {
			lenAvailable = framesPerBuffer;
			avail = lenAvailable;
		}
	}
	else {
		lenAvailable = 0;
		avail = 0;
	}

	// Play something
	if (lenAvailable > 0) {
		provider->GetAudio(outputBuffer,player->playPos,lenAvailable);
	}

	// Pad end with blank
	if (avail < (uint64_t) framesPerBuffer) {
		//provider->softStop = true;
	}

	// Set volume
	short *output = (short*) outputBuffer;
	for (unsigned int i=0;i<avail;i++) output[i] = MID(-(1<<15),int(output[i] * player->GetVolume()),(1<<15)-1);

	// Fill rest with blank
	for (unsigned int i=avail;i<framesPerBuffer;i++) output[i]=0;

	// Set play position (and real one)
	player->playPos += framesPerBuffer;
	player->realPlayPos = (__int64)(Pa_StreamTime(player->stream) - player->paStart) + player->startPos;

	// Cap to start if lower
	return end;
}
开发者ID:BackupTheBerlios,项目名称:aegisub-svn,代码行数:47,代码来源:audio_player_portaudio.cpp

示例2: getMaxScrollX

void Tabs::setScrollX(int scroll_x)
{
  int max_x = getMaxScrollX();

  scroll_x = MID(0, scroll_x, max_x);
  if (m_scrollX != scroll_x) {
    m_scrollX = scroll_x;
    calculateHot();
    invalidate();
  }

  // We need scroll buttons?
  if (max_x > 0) {
    // Add childs
    if (!HAS_ARROWS(this)) {
      addChild(m_button_left);
      addChild(m_button_right);
      invalidate();
    }

    /* disable/enable buttons */
    m_button_left->setEnabled(m_scrollX > 0);
    m_button_right->setEnabled(m_scrollX < max_x);

    /* setup the position of each button */
    {
      JRect rect = jwidget_get_rect(this);
      JRect box = jrect_new(rect->x2-ARROW_W*2, rect->y1,
                            rect->x2-ARROW_W, rect->y2-2);
      jwidget_set_rect(m_button_left, box);

      jrect_moveto(box, box->x1+ARROW_W, box->y1);
      jwidget_set_rect(m_button_right, box);

      jrect_free(box);
      jrect_free(rect);
    }
  }
  // Remove buttons
  else if (HAS_ARROWS(this)) {
    removeChild(m_button_left);
    removeChild(m_button_right);
    invalidate();
  }
}
开发者ID:optigon,项目名称:aseprite,代码行数:45,代码来源:tabs.cpp

示例3: Update

void Update(int u, int l, int r, int change)
{
    if(f[u].label == change) return ;
    if(l == f[u].l && r == f[u].r) {
        f[u].label = change;
        return ;
    }
    if(f[u].label) {
        put_down(u);
    }
    int mid = MID(f[u].l, f[u].r);
    if(r <= mid) Update(L(u), l, r, change);
    else if(mid < l) Update(R(u), l, r, change);
    else {
        Update(L(u), l, mid, change);
        Update(R(u), mid+1, r, change);
    }
}
开发者ID:keroro520,项目名称:ACM,代码行数:18,代码来源:A.cpp

示例4: Query

int Query(Tnode* T,int u,int l,int r)
{
    int delta = T[u].delta;
    if(T[u].l == l && T[u].r == r)
        return T[u].sum + delta*(r-l);
    T[L(u)].delta += delta;
    T[R(u)].delta += delta;
    T[u].sum += delta*(T[u].r-T[u].l);
    T[u].delta = 0;
    int mid = MID(T[u].l,T[u].r);
    if(l >= mid)
        return Query(T,R(u),l,r);
    else
        if(r <= mid)
            return Query(T,L(u),l,r);
        else
            return Query(T,L(u),l,mid) + Query(T,R(u),mid,r);
}
开发者ID:cxlove,项目名称:ACM_ICPC,代码行数:18,代码来源:hdoj_4267.cpp

示例5: window

void PasteTextCommand::onExecute(Context* ctx)
{
    Editor* editor = current_editor;
    if (editor == NULL)
        return;

    Preferences& pref = Preferences::instance();
    PasteTextWindow window(pref.textTool.fontFace(),
                           pref.textTool.fontSize(),
                           pref.colorBar.fgColor());

    window.userText()->setText(last_text_used);

    window.openWindowInForeground();
    if (window.getKiller() != window.ok())
        return;

    last_text_used = window.userText()->getText();

    std::string faceName = window.faceValue();
    int size = window.sizeValue();
    size = MID(1, size, 999);
    pref.textTool.fontFace(faceName);
    pref.textTool.fontSize(size);

    try {
        std::string text = window.userText()->getText();
        app::Color appColor = window.fontColor()->getColor();
        doc::color_t color = doc::rgba(appColor.getRed(),
                                       appColor.getGreen(),
                                       appColor.getBlue(),
                                       appColor.getAlpha());

        doc::ImageRef image(render_text(faceName, size, text, color));
        if (image) {
            editor->pasteImage(image.get());
        }
    }
    catch (const std::exception& ex) {
        ui::Alert::show(PACKAGE
                        "<<%s"
                        "||&OK", ex.what());
    }
}
开发者ID:ripesunflower,项目名称:aseprite,代码行数:44,代码来源:cmd_paste_text.cpp

示例6: Object

Sprite::Sprite(PixelFormat format, int width, int height, int ncolors)
  : Object(ObjectType::Sprite)
  , m_document(NULL)
  , m_format(format)
  , m_width(width)
  , m_height(height)
  , m_frames(1)
  , m_frameTags(this)
{
  ASSERT(width > 0 && height > 0);

  m_frlens.push_back(100);      // First frame with 100 msecs of duration
  m_folder = new LayerFolder(this);

  // Generate palette
  switch (format) {
    case IMAGE_GRAYSCALE: ncolors = 256; break;
    case IMAGE_BITMAP: ncolors = 2; break;
  }

  Palette pal(frame_t(0), ncolors);

  switch (format) {

    // For black and white images
    case IMAGE_GRAYSCALE:
    case IMAGE_BITMAP:
      for (int c=0; c<ncolors; c++) {
        int g = 255 * c / (ncolors-1);
        g = MID(0, g, 255);
        pal.setEntry(c, rgba(g, g, g, 255));
      }
      break;
  }

  // Initial RGB map
  m_rgbMap = NULL;

  // The transparent color for indexed images is 0 by default
  m_transparentColor = 0;

  setPalette(&pal, true);
}
开发者ID:airways,项目名称:aseprite,代码行数:43,代码来源:sprite.cpp

示例7: clearBlock

void flash25spi::clearSector(unsigned int addr) {
    if (_sectorSize == 0) {
        clearBlock(addr);
        return;
    }
        
    addr &= ~(_sectorSize-1);
 
    enableWrite();
    _enable->write(0);
    wait_us(1);
    _spi->write(0x20);
    _spi->write(HIGH(addr));
    _spi->write(MID(addr));
    _spi->write(LOW(addr));
    wait_us(1);
    _enable->write(1);
    waitForWrite();
}
开发者ID:HeydayGuan,项目名称:Nucleo_RemoteUpdate,代码行数:19,代码来源:flash25spi.cpp

示例8: _xwin_mousedrv_init

/* _xwin_mousedrv_init:
 *  Initializes the mickey-mode driver.
 */
static int _xwin_mousedrv_init(void)
{
   int num_buttons;
   unsigned char map[8];

   num_buttons = _xwin_get_pointer_mapping(map, sizeof(map));
   num_buttons = MID(2, num_buttons, 3);

   last_xspeed = -1;
   last_yspeed = -1;

   XLOCK();

   _xwin_mouse_interrupt = _xwin_mousedrv_handler;

   XUNLOCK();

   return num_buttons;
}
开发者ID:dodamn,项目名称:pkg-allegro4.2,代码行数:22,代码来源:xmouse.c

示例9: Object

Sprite::Sprite(PixelFormat format, int width, int height, int ncolors)
  : Object(OBJECT_SPRITE)
  , m_format(format)
  , m_width(width)
  , m_height(height)
  , m_frames(1)
{
  ASSERT(width > 0 && height > 0);

  m_frlens.push_back(100);      // First frame with 100 msecs of duration
  m_stock = new Stock(format);
  m_folder = new LayerFolder(this);

  // Generate palette
  Palette pal(FrameNumber(0), ncolors);

  switch (format) {

    // For colored images
    case IMAGE_RGB:
    case IMAGE_INDEXED:
      pal.resize(ncolors);
      break;

    // For black and white images
    case IMAGE_GRAYSCALE:
    case IMAGE_BITMAP:
      for (int c=0; c<ncolors; c++) {
        int g = 255 * c / (ncolors-1);
        g = MID(0, g, 255);
        pal.setEntry(c, rgba(g, g, g, 255));
      }
      break;
  }

  // Initial RGB map
  m_rgbMap = NULL;

  // The transparent color for indexed images is 0 by default
  m_transparentColor = 0;

  setPalette(&pal, true);
}
开发者ID:felipeita,项目名称:aseprite,代码行数:43,代码来源:sprite.cpp

示例10: sample_dither_filter

/* Dithering with noise shaping filter. Set shape = 0 for no shaping. */
static void sample_dither_filter(float *src, long size, float shape) {
	float r1 = 0, r2 = 0;
	float s1 = 0, s2 = 0; /* Feedback buffer */
	float o = 0.5f / 255;
	float tmp;
	int i;

	for (i = 0; i < size; i++) {
		r2 = r1;
		r1 = rand() / (float)RAND_MAX;

		tmp = src[i] + shape * (s1 + s1 - s2);
		src[i] = tmp + o * (r1 - r2);
		src[i] = MID(-1.0f, src[i], 1.0f);

		s2 = s1;
		s1 = tmp - src[i];
	}
	return;
}
开发者ID:AkumaKing,项目名称:Xeu,代码行数:21,代码来源:sample.c

示例11: layer_render

void layer_render(const Layer* layer, Image* image, int x, int y, FrameNumber frame)
{
  if (!layer->isVisible())
    return;

  switch (layer->type()) {

    case ObjectType::LayerImage: {
      const Cel* cel = static_cast<const LayerImage*>(layer)->getCel(frame);
      Image* src_image;

      if (cel) {
        ASSERT((cel->imageIndex() >= 0) &&
               (cel->imageIndex() < layer->sprite()->stock()->size()));

        src_image = cel->image();
        ASSERT(src_image != NULL);

        ASSERT(src_image->maskColor() == layer->sprite()->transparentColor());

        composite_image(image, src_image,
          cel->x() + x,
          cel->y() + y,
          MID(0, cel->opacity(), 255),
          static_cast<const LayerImage*>(layer)->getBlendMode());
      }
      break;
    }

    case ObjectType::LayerFolder: {
      LayerConstIterator it = static_cast<const LayerFolder*>(layer)->getLayerBegin();
      LayerConstIterator end = static_cast<const LayerFolder*>(layer)->getLayerEnd();

      for (; it != end; ++it)
        layer_render(*it, image, x, y, frame);

      break;
    }

  }
}
开发者ID:jjconti,项目名称:aseprite,代码行数:41,代码来源:layer.cpp

示例12: layer_render

void layer_render(const Layer* layer, Image* image, int x, int y, FrameNumber frame)
{
  if (!layer->isReadable())
    return;

  switch (layer->getType()) {

    case GFXOBJ_LAYER_IMAGE: {
      const Cel* cel = static_cast<const LayerImage*>(layer)->getCel(frame);
      Image* src_image;

      if (cel) {
        ASSERT((cel->getImage() >= 0) &&
               (cel->getImage() < layer->getSprite()->getStock()->size()));

        src_image = layer->getSprite()->getStock()->getImage(cel->getImage());
        ASSERT(src_image != NULL);

        src_image->mask_color = layer->getSprite()->getTransparentColor();

        image_merge(image, src_image,
                    cel->getX() + x,
                    cel->getY() + y,
                    MID (0, cel->getOpacity(), 255),
                    static_cast<const LayerImage*>(layer)->getBlendMode());
      }
      break;
    }

    case GFXOBJ_LAYER_FOLDER: {
      LayerConstIterator it = static_cast<const LayerFolder*>(layer)->getLayerBegin();
      LayerConstIterator end = static_cast<const LayerFolder*>(layer)->getLayerEnd();

      for (; it != end; ++it)
        layer_render(*it, image, x, y, frame);

      break;
    }

  }
}
开发者ID:bradparks,项目名称:aseprite,代码行数:41,代码来源:layer.cpp

示例13: delayed_free

static void
delayed_free(void *uptr, const char* file, int line)
{
    void *mptr;
    void *olduptr = free_delay[free_delay_pos];
    size_t nbytes;
    if ( uptr==NULL )
        return;
    mptr = user2malloc_(uptr);
    memory_check(uptr, MID(mptr), MFILE(mptr), MLINE(mptr), file, line);
    if ( olduptr!=NULL ) {
        actual_free(olduptr, file, line);
    }
    free_delay[free_delay_pos] = uptr;
    free_delay_pos++;
    free_delay_pos = free_delay_pos % MAX_FREE_DELAY_COUNT;
    nbytes = -user_nsize1_(uptr);
#ifdef FREED_CHAR
    (void)memset(uptr, FREED_CHAR, (size_t)nbytes);
#endif
}
开发者ID:4T-Shirt,项目名称:OpenJDK-Research,代码行数:21,代码来源:debug_malloc.c

示例14: debug_malloc_verify

void
debug_malloc_verify(const char *file, int line)
{
    void           *mptr;

#ifdef MAX_FREE_DELAY_COUNT
    delayed_free_all(file,line);
#endif

    if (!malloc_watch) {
        return;
    }
    mptr = first_warrant_mptr;
    if (mptr != NULL) {
        /* Check all this memory first */
        do {
            memory_check(malloc2user_(mptr), MID(mptr), MFILE(mptr), MLINE(mptr), file, line);
            mptr = warrant_link_(mptr);
        } while (mptr != NULL);
    }
}
开发者ID:4T-Shirt,项目名称:OpenJDK-Research,代码行数:21,代码来源:debug_malloc.c

示例15: Updata

void Updata(Tnode* T,int u,int l,int r,int up)
{
    if(T[u].l == l && T[u].r == r)
    {
        T[u].delta += up;
        return ;
    }
    else
        T[u].sum += up*(r-l);
    int mid = MID(T[u].l,T[u].r);
    if(l >= mid)
        Updata(T,R(u),l,r,up);
    else
        if(r <= mid)
            Updata(T,L(u),l,r,up);
        else
        {
            Updata(T,L(u),l,mid,up);
            Updata(T,R(u),mid,r,up);
        }
}
开发者ID:cxlove,项目名称:ACM_ICPC,代码行数:21,代码来源:hdoj_4267.cpp


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