📄 main.c
字号:
/* * srgplay - MIDI file player * 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 <unistd.h>#include <fcntl.h>#include <sys/ioctl.h>#include <stdlib.h>#include <string.h>#include <signal.h>#include "config.h"#include "player.h"#include "sequencer.h"#include "seq_serial.h"#include "seq_oss_sio.h"#include "seq_smf0.h"#include "defines.h"#include "option.h"u_char port2dev[16]={ PORT_A, PORT_B, PORT_C, PORT_D, PORT_E, PORT_F, PORT_A, PORT_A, PORT_A, PORT_A, PORT_A, PORT_A, PORT_A, PORT_A, PORT_A, PORT_A};Sequencer *aSequencer;MIDIplayer *player;OPTION opt;char MIDIplayer::stop=FALSE;char MIDIplayer::next=FALSE;void nextSong(int);void prevSong(int);void stopSong(int);intmain(int argc, char *argv[]){ signal(SIGUSR1, nextSong); signal(SIGUSR2, prevSong); signal(SIGINT , stopSong); signal(SIGTERM, stopSong); signal(SIGKILL, stopSong); signal(SIGSTOP, exit); opt.getOption(argc, argv); port2dev[0]=opt.PortAdevice; port2dev[1]=opt.PortBdevice; port2dev[2]=opt.PortCdevice; port2dev[3]=opt.PortDdevice; port2dev[4]=opt.PortEdevice; port2dev[5]=opt.PortFdevice; G36_Player g36; R36_Player rcp; SMF_Player smf;#ifndef NO_OSS if (opt.Output==Serial)/*default write uart*/ {#endif aSequencer = new Sequencer_Serial; if(aSequencer->open(opt.SerialDevice, SEQBUFFER_SIZE)<0) return -1;#ifndef NO_OSS } else if (opt.Output==OSS) { aSequencer = new Sequencer;/*write OSS*/ if(aSequencer->open(opt.SequencerDevice, SEQBUFFER_SIZE)<0) return -1; } else { aSequencer = new Seq_OSS_Serial; if(aSequencer->open(opt.SerialDevice, SEQBUFFER_SIZE)<0) return -1; }#endif int devnum; if((devnum=aSequencer->checkMidiDevice())<1) { if (devnum==0) printf("no midi device\n"); // cout << "no midi device" << endl; aSequencer->close(); return -1; } u_long k; for(k=0;k<16;k++) { if(port2dev[k]>=aSequencer->NumOfDevice()) { port2dev[k] |= 0x80; } } int rtn; char *DataName; for(k=0;k<opt.repeat;k++) { opt.setIndexToHead(); if(opt.shuffle==TRUE) opt.shuffleData(); while((DataName=opt.NextData())!=NULL) { // 不富リセット if (opt.ResetDataName[0]!='\0') { if ((rtn = smf.load(opt.ResetDataName))>=0) player = &smf; else if ((rtn = rcp.load(opt.ResetDataName))>=0) player = &rcp; else if ((rtn = g36.load(opt.ResetDataName))>=0) player = &g36; if(rtn>=0) { aSequencer->reset(); player->init(); player->play(); player->clear(); usleep(80*1000); } } if((rtn = smf.load(DataName))>=0) player=&smf; else if((rtn = rcp.load(DataName))>=0) player=&rcp; else if((rtn = g36.load(DataName))>=0) player=&g36; if(rtn>=0) {# ifdef SHOW_FILEINFO printf("filename:%s\n", filename); // cout << "filename:" << DataName << endl;# endif aSequencer->reset(); player->init(); player->play(); player->clear(); if(opt.wait>0) usleep(opt.wait*1000); } else { switch (rtn) { case -1: printf("%s : open error \n",DataName); // cout << DataName << " : open error " << endl; break; case -2: printf("%s : unknown format\n", DataName); // cout << DataName << " : unknown format" << endl; break; case -3: printf("%s :broken file?\n", DataName); // cout << DataName << " : broken file?" << endl; break; case -4: printf("memory allocation error\n"); // cout << "memory allocation error" << endl; aSequencer->close(); return rtn; break; default: printf("error \n"); // cout << "error" << endl; aSequencer->close(); return rtn; break; } } } } aSequencer->close(); return 0;}void nextSong(int signum){ player->next=TRUE; signal(signum, nextSong);}void prevSong(int signum){ opt.setIndexToPrevData(); player->next=TRUE; signal(signum, prevSong);}void stopSong(int){ signal (SIGINT, SIG_IGN); player->stop=TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -