⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 seq_serial.c

📁 一个很好的c++ midi解码算法,不依赖于任何平台.
💻 C
字号:
/* *  seq_serial.cc *  Copyright (C) 1998-2000 SAKAI Katsuya * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include <stdio.h>  // #include <iostream.h>#include <sys/ioctl.h>#include <unistd.h>#include <fcntl.h>#include <stdio.h>#include <termios.h>#include "defines.h"#include "config.h"#include "seq_serial.h"#include "extern.h"int Sequencer_Serial::open(char *seqdev, int buflen){  opt.useSerial=TRUE;  if(flagOpen == TRUE) return -1;  if((seqfd = ::open(seqdev, O_RDWR|O_NDELAY))<0)    {      perror("cannot open device");      return -2;    }  _seqbuf = new u_char [buflen];  if(!_seqbuf)    {      printf("allocation error\n"); // cerr << "allocation error" << endl;      return -3;    }  _seqbuflen = buflen;  _seqbufptr = 0;  struct termios tio;  if (tcgetattr (seqfd, &tio) < 0)    {      return -1;    }  tio_orig = tio;  tio.c_iflag = 0;  tio.c_oflag = 0;  tio.c_cflag = CS8 | CREAD | CLOCAL | CRTSCTS;  tio.c_lflag = 0;  cfsetispeed(&tio, B38400);  cfsetospeed(&tio, B38400);  if (tcsetattr (seqfd, TCSANOW, &tio) < 0)    {      perror(" ");      return -3;    }  flagOpen = TRUE;  return 0;}int Sequencer_Serial::close(){  if(flagOpen != TRUE) return -1;  stopTimer();  delete [] _seqbuf;  flagOpen = FALSE;  if (tcsetattr (seqfd, TCSANOW, &tio_orig) < 0)    perror(" ");  ::close(seqfd);  return 0;}int Sequencer_Serial::checkMidiDevice(){  numberOfDevice = 1;  return numberOfDevice;}void Sequencer_Serial::reset(){  seqbuf_dump();  _seqbufptr = 0;}void Sequencer_Serial::sync(){  seqbuf_dump();}void Sequencer_Serial::startTimer(){#ifdef RUNNING_ST  for(int n=0;n<16;n++) clearStatus(n);#endif  LastOutputPort = 0;  gettimeofday(&starttime, NULL);  ctrlrate = 1000000;  LastTick = 0;  CurrentTime = 0.;  }void Sequencer_Serial::stopTimer(){  changePort (port2dev[0], 0);  LastOutputPort = 0;  seqbuf_dump();}void Sequencer_Serial::seq_midiout(u_char dev, u_char dat){  if (_seqbufptr>=_seqbuflen) seqbuf_dump();  _seqbuf[_seqbufptr] = dat;  _seqbufptr++;}void Sequencer_Serial::seq_waittime(u_long tick){  static long waittime;  seqbuf_dump();  gettimeofday (&now, NULL);  waittime = (long)tick - (now.tv_usec-starttime.tv_usec)    - (now.tv_sec-starttime.tv_sec)*1000000;  if(waittime>999)    usleep (waittime);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -