home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 November / CMCD1104.ISO / Software / Complet / ZynAddFX / Setup_ZynAddSubFX-2.1.1.exe / Dump.C < prev    next >
Encoding:
C/C++ Source or Header  |  2004-03-05  |  2.6 KB  |  101 lines

  1. /*
  2.   ZynAddSubFX - a software synthesizer
  3.  
  4.   Dump.C - It dumps the notes to a text file
  5.  
  6.   Copyright (C) 2002-2004 Nasca Octavian Paul
  7.   Author: Nasca Octavian Paul
  8.  
  9.   This program is free software; you can redistribute it and/or modify
  10.   it under the terms of version 2 of the GNU General Public License 
  11.   as published by the Free Software Foundation.
  12.  
  13.   This program is distributed in the hope that it will be useful,
  14.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.   GNU General Public License (version 2) for more details.
  17.  
  18.   You should have received a copy of the GNU General Public License (version 2)
  19.   along with this program; if not, write to the Free Software Foundation,
  20.   Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  21. */
  22. #include <stdlib.h>
  23. #include <time.h>
  24. #include "Util.h"
  25. #include "Dump.h"
  26.  
  27. Dump dump;
  28.  
  29. Dump::Dump(){
  30.     file=NULL;
  31.     tick=0;
  32.     k=0;
  33.     keyspressed=0;
  34.     startnow();
  35. };
  36.  
  37. Dump::~Dump(){
  38.     if (file!=NULL) {
  39.     double duration=(double)tick*(double) SOUND_BUFFER_SIZE/(double) SAMPLE_RATE;
  40.     fprintf(file,"\n# statistics: duration = %d seconds; keyspressed = %d\n\n\n\n",(int) duration,keyspressed);
  41.     fclose(file);
  42.     };
  43. };
  44.  
  45. void Dump::startnow(){
  46.     if (file!=NULL) return;//the file is already open
  47.     
  48.     if (config.cfg.DumpNotesToFile!=0){
  49.     if (config.cfg.DumpAppend!=0) file=fopen(config.cfg.DumpFile,"a");
  50.         else file=fopen(config.cfg.DumpFile,"w");
  51.     
  52.     if (file==NULL) return;
  53.     if (config.cfg.DumpAppend!=0) fprintf(file,"%s","#************************************\n");
  54.  
  55.     time_t tm=time(NULL);    
  56.         
  57.     fprintf(file,"#date/time = %s\n",ctime(&tm));
  58.     fprintf(file,"#1 tick = %g milliseconds\n",SOUND_BUFFER_SIZE*1000.0/SAMPLE_RATE);
  59.     fprintf(file,"SAMPLERATE = %d\n",SAMPLE_RATE);
  60.     fprintf(file,"TICKSIZE = %d #samples\n",SOUND_BUFFER_SIZE);
  61.     fprintf(file,"\n\nSTART\n");
  62.     };
  63. };
  64.  
  65. void Dump::inctick(){
  66.     tick++;
  67. };
  68.  
  69.  
  70. void Dump::dumpnote(char chan,char note, char vel){
  71.     if (file==NULL) return;
  72.     if (vel==0) fprintf(file,"n %d -> %d %d \n",tick,chan,note);//note off
  73.     else fprintf(file,"N %d -> %d %d %d \n",tick,chan,note,vel);//note on
  74.     
  75.     if (vel!=0) keyspressed++;
  76. #ifndef JACKAUDIOOUT
  77.     if (k++>25) {
  78.     fflush(file);
  79.     k=0;
  80.     };
  81. #endif
  82. };
  83.  
  84. void Dump::dumpcontroller(char chan,unsigned int type,int par){
  85.     if (file==NULL) return;
  86.     switch(type){
  87.     case C_pitchwheel:fprintf(file,"P %d -> %d %d\n",tick,chan,par);
  88.         break;
  89.     default:fprintf(file,"C %d -> %d %d %d\n",tick,chan,type,par);
  90.         break;
  91.     };
  92. #ifndef JACKAUDIOOUT
  93.     if (k++>25) {
  94.     fflush(file);
  95.     k=0;
  96.     };
  97. #endif
  98. };
  99.  
  100.  
  101.