(c)  騭, ᪢

ZXNet : 500:95/462.53
E-mail: bestview@mtu-net.ru
WWW   : http://www.ivr.da.ru

        浪    Impulse Tracker
       

(".  " 7/2005)




     뢠 㦭  冷   몠쭮
㫥, ᠭ  Impulse Tracker, - ਬ, ⮡ 
  㬥⮬ ᯮ 冷  祭
᫥饣 ।஢.   ᠬ Impulse Tracker 
㤮 ᯮᮡ  ᤥ. , 筮,  㦭
१   ஢ ,   让 
筮 ࠡ.
     ஡   ୥ ⮢ ணࠬ  
浪   it-䠩    㯮  . ,
ᯥ譮 - , ਬ,  xm-䠩 (Fast Tracker) ⠪
ணࠬ 뫠 㦥. 祣  ⠢,  
ணࠬ ᠬ. :)  ⮣  㦥 室  ଠ
㫥 IT,   ᠫ  Pro Tracker 3 -> Impulse
Tracker, ⠪     ᫮.


 ணࠬ


/* =============================
     File: "reord_it.c"
     Compiler: Turbo C 2.0
 ============================= */

#include <stdio.h>
#include <ctype.h>
#include <string.h>

#define byte unsigned char    /* 1 .  */
#define word unsigned int     /* 2 . */

/* ==================== ᠭ 㭪権 ==================== */

int get_new_order (char* s);
int read_2 (char** s, int* n1, int* n2);
FILE* fopen_1 (char* name, char* mode);
void fclose_1 (FILE* f);
int fgetc_1 (FILE* f);
void fputc_1 (int c, FILE* f);
void fseek_1 (FILE* f, long offset, int whence);

/* ======================= ६ ======================= */

int new_order[64];      /*     ࠭
                             . */
byte pan_vol_old[128];  /* ᨢ  묨  묨   */
byte pan_vol_new[128];  /* 祭ﬨ 砫쭮 ࠬ */
                        /*  ஬ .          */

/* ================== 諠 ᠬ ணࠬ ================== */

int main (int argc, char *argv[])
{
 FILE *f_src;
 int i,j;

 printf ("\n\
Ŀ\n\
Program for reordering channels in Impulse Tracker modules\n\
(c) Ivan Roshin, Moscow, 18 Jul 2004                      \n\
E-mail: bestview@mtu-net.ru      WWW: http://www.ivr.da.ru\n\
\n\
");

 if (argc!=3)
 {
  printf ("\n\
Syntax: reord_it.exe NewChannel=OldChannel,... it-file\n\n\
Example: for swap channels 2 and 5, and swap channels 1 and 3\n\
         in it-file 'demo.it', type:\n\n\
reord_it.exe 2=5,5=2,1=3,3=1 demo.it\n\n");
  exit(1);
 }

 /* ࠡ뢠 㪠   ப 㬥,
    ।騩  冷 ᯮ . */

 if (get_new_order(argv[1]))
 {printf ("\nIncorrect argument!\n\n"); exit (1);}

 /* 뢠 室 䠩. */

 f_src=fopen_1(argv[2],"rb+");
 printf ("File: %s  ",argv[2]);

/* ===================  bak-䠩 =================== */

 {
  FILE *f_bak;
  char name_bak[13];

  /* ନ㥬  bak-䠩   室 䠩. */

  i=0;
  while (!((argv[2][i]=='.')||(argv[2][i]==0)))
  {
   name_bak[i]=argv[2][i];
   i++;
   if (i>8) {printf ("\nIncorrect file name!\n\n"); exit (1);}
  }
  strcpy(name_bak+i,".bak");

  /* 㥬 ᮤন 室 䠩  bak-䠩. */

  f_bak=fopen_1(name_bak,"wb");
  while ((i=fgetc_1(f_src))!=EOF) fputc_1 (i,f_bak);
  fclose_1(f_bak);
 }

/* =================== ࠡ⪠ it-䠩 =================== */

 /* ஢ઠ ᨣ:  4  - "IMPM". */

 {
  byte signature[4];

  fseek_1 (f_src,0L,SEEK_SET);
  if (fread(&signature,(size_t)4,1,f_src)!=1)
  {printf ("\nRead error!\n\n"); exit (1);}
  if (strncmp(signature,"IMPM",(size_t)4)!=0)
  {printf ("\nIncorrect file format!\n\n"); exit (1);}
 }

 /* ⠥ 砫 祭 ࠬ  ஬ ,
    塞  冷  ᮮ⢥⢨  ᨢ new_order
     뢠 ⭮. */

 fseek_1 (f_src,0x40L,SEEK_SET);
 if (fread(&pan_vol_old,(size_t)128,1,f_src)!=1)
 {printf ("\nRead error!\n\n"); exit (1);}

 for (i=0;i<64;i++)
 {
  pan_vol_new[new_order[i]-1]=pan_vol_old[i];      /* Panning */
  pan_vol_new[new_order[i]-1+64]=pan_vol_old[i+64]; /* Volume */
 }

 fseek_1(f_src,0x40L,SEEK_SET);
 if (fwrite(&pan_vol_new,(size_t)128,1,f_src)!=1)
 {printf ("\nWrite error!\n\n"); exit (1);}

 /* ࠡ⪠ ୮. */

 {
  word OrdNum;    /* - 権. */
  word InsNum;    /* - 㬥⮢. */
  word SmpNum;    /* - . */
  word PatNum;    /* - ୮. */
  long current_p; /* 饭  ⥪饣 ୠ. */
  word rows;      /* - ப  ⥪饬 ୥. */

  fseek_1(f_src,0x20L,SEEK_SET);
  OrdNum=fgetc_1(f_src); OrdNum|=fgetc_1(f_src)<<8;
  InsNum=fgetc_1(f_src); InsNum|=fgetc_1(f_src)<<8;
  SmpNum=fgetc_1(f_src); SmpNum|=fgetc_1(f_src)<<8;
  PatNum=fgetc_1(f_src); PatNum|=fgetc_1(f_src)<<8;

  for (i=0;i<PatNum;i++)
  {
   fseek_1(f_src,0xC0L+OrdNum+InsNum*4L+SmpNum*4L+i*4L,SEEK_SET);

   /* ⠥ ᬥ饭  ⥪饣 ୠ. */

   current_p=fgetc_1(f_src);
   current_p|=(long)fgetc_1(f_src)<<8;
   current_p|=(long)fgetc_1(f_src)<<16;
   current_p|=(long)fgetc_1(f_src)<<24;

   /* ᫨ ᬥ饭 ࠢ  - , ⮩ . */

   if (current_p==0) continue;

   /* 樮㥬  砫 ୠ + 2 , ⠥
      - ப  ୥  ய᪠ 4 . */

   fseek_1(f_src,current_p+2,SEEK_SET);
   rows=fgetc_1(f_src); rows|=fgetc_1(f_src)<<8;
   fseek_1(f_src,4L,SEEK_CUR);

   /* ࠡ⪠ ப ୠ. */

   for (j=0;j<rows;j++)
   {
    byte old_mask_var[64];
    byte ch_var;
    byte channel;
    byte mask_var;

    /* ࠡ⪠  ப. */

    while ((ch_var=fgetc_1(f_src))!=0)
    {
     /*    ⠭  -  .
        塞   ⠡ new_order  뢠 ⭮,
        ࠭  ⮬ 祭 襣 . */

     channel=(ch_var-1)&63;
     ch_var=new_order[channel]|(ch_var&128);
     fseek_1(f_src,-1L,SEEK_CUR);
     fputc_1 (ch_var,f_src);
     fseek_1(f_src,0L,SEEK_CUR); /* 祬-  ⮣
                                     ࠡ⠥. :( */
     if (ch_var&128)
     {
      mask_var=fgetc_1(f_src);
      old_mask_var[channel]=mask_var;
     }
     else mask_var=old_mask_var[channel];

     /* ய᪠ 塞  ப ୠ. */

     if (mask_var&1) fgetc_1 (f_src);
     if (mask_var&2) fgetc_1 (f_src);
     if (mask_var&4) fgetc_1 (f_src);
     if (mask_var&8) {fgetc_1 (f_src); fgetc_1 (f_src);}
    }
   }
  }
 }
 fclose_1 (f_src);
 printf ("OK!\n\n");
 exit (0);
}

/* =============================================================
   㭪 get_new_order - ࠡ⪠ 㪠  
   ப 㬥, ।饣  冷 ᯮ
    (..  ப  "7=2,2=15,14=3,...",
   ஥  ᭮   ᨢ new_order,  
     ࠭   ,  ஢ઠ
   ४⭮ 祭 ᨢ).
   室: s - 㪠⥫  ࠡ뢠 㬥.
   室: 0 - OK, 1 - 訡.
 ============================================================ */

int get_new_order (char* s)
{
 int n1,n2;
 int i,j;

 for (i=0;i<64;i++) new_order[i]=i+1;
 while (*s!=0) /*  ப  稫. */
 {
  if (read_2(&s,&n1,&n2)) return 1;
  new_order[n2-1]=n1;
 }

 /* ஢ઠ ४⭮ 祭 ᨢ new_order ( 
    ஢ઠ,  ⨫  짮⥫ 訡  㪠
     浪 ᯮ ):  ᨢ 
    ⢮   ᥫ  1  64 (  ᨢ
        ᥫ  1  64   浪).
     ᠬ , ᫨  ᨢ  -   ᥫ,
     ᮮ⢥饬  ନ㥬   㤥
    ᮮ⢥⢮   室 ,  
    ⨬,    ⮫쪮 冷 . */

 for (i=1;i<=64;i++)
 {
  for (j=0;j<64;j++) {if (new_order[j]==i) goto m1;}
  return 1;
  m1:;
 }
 return 0;
}

/* =============================================================
   㭪 read_2 - ⥭ ࢮ  祭  ப 
   "7=2,2=15,14=3,...".
   室: s -  㪠⥫  ப (᫥ ᯥ譮 室
          㭪樨  㪠⥫  ⠪, ⮡
         㪠뢠  ᫥  祭  ப - ..
          "2=15,14=3,..."); n1  n2 - ,   
          ࢮ  ஥ ⠭ 祭 (
         ଠ int).
   室: 0 - OK, 1 - 訡.
 ============================================================ */

int read_2 (char** s, int* n1, int* n2)
{
 if (isdigit(**s)) {*n1=**s-'0'; (*s)++;} else return 1;
 if (isdigit(**s)) {*n1=*n1*10+**s-'0'; (*s)++;}
 if (**s!='=') return 1;
 (*s)++;
 if (isdigit(**s)) {*n2=**s-'0'; (*s)++;} else return 1;
 if (isdigit(**s)) {*n2=*n2*10+**s-'0'; (*s)++;}
 if (**s==',') {(*s)++; return 0;}
 if (**s==0) return 0; else return 1;
}

/* =============================================================
     㭪権  ࠡ  䠩 (fopen,
   fclose, fgetc, fputc, fseek).  訡 뢠 믮
   ணࠬ,  ᮮ⢥饥 ᮮ饭; ⠪ ࠧ,
   ᫥ 맮  㭪権   ஢, 뫠  訡.
 ============================================================ */

FILE* fopen_1 (char* name, char* mode)
{
 FILE* f;
 char* s;
 char* s1="read";
 char* s2="write";

 f=fopen(name,mode);
 if (f==NULL)
 {
  if (mode[0]=='r') s=s1; else s=s2;
  printf ("\nCan't open file \"%s\" for %s!\n\n",name,s);
  exit (1);
 }
 return (f);
}

void fclose_1 (FILE* f)
{
 if (fclose(f)==EOF) {printf ("\nClose error!\n\n"); exit (1);}
}

int fgetc_1 (FILE* f)
{
 int c;
 c=fgetc(f);
 if ferror(f) {printf ("\nRead error!\n\n"); exit (1);}
 return (c);
}

void fputc_1 (int c, FILE* f)
{
 if (fputc(c,f)==EOF) {printf ("\nWrite error!\n\n"); exit (1);}
}

void fseek_1 (FILE* f, long offset, int whence)
{
 if (fseek(f,offset,whence)!=0)
 {printf ("\nPosition error!\n\n"); exit (1);}
}


㪮⢮ 짮⥫


    ଠ  ப:

reord_it.exe ଠ___浪_ it-file

    ᫨  ணࠬ  㬥⮢,  뤠 
ࠢ  ࠡ  .
    ଠ   浪  ।⠢ ᮡ
ࠧ ⮩  ᥫ  NewChannel=OldChannel, 
NewChannel -  , 㤠 㤥 ७ᥭ ଠ,
 OldChannel -  , 㤠 㤥 ७ᥭ 
ଠ.   㪠뢠 ᮮ⢥⢨   室
 砥 . ਬ,   ⠬ ᮤন
1  2 , ⮣   ப 㪠뢠 "1=2,2=1" (
祪,  ஡ ᫥ ⮩):    ७
ଠ  ண,   ன -  ࢮ.  
 : "2=1,1=2" - १ 㤥 ⥬  ᠬ.
     ਬ: , ⮡  ࢮ   , 
࠭ 뫮  ஬,  ஬ - ,  ࠭ 뫮 
쥬,   쥬 - ,  ࠭ 뫮  ࢮ.  
ப 㪠뢠 "1=2,2=3,3=1".
     :  ଠ ६頥  
 X   Y,  ଠ,  뫠 ࠭  
X, ⠪   ६饭  - : ணࠬ
⮫쪮  冷 ,     ଠ 
 ய! ⮬ ࠢ쭮 㤥 㪠  
ப, ᪠, "1=2,2=3", ⠪  ⮣ ᭮, 㤠 ३
ଠ   1. ணࠬ ᫥  ⨬   
樨 뤠 ᮮ饭 "Incorrect argument!".
    ࠡ뢠 it-䠩  室  ⥪饬 ⠫.
। 砫  ࠡ⪨ ணࠬ ᮧ  १ࢭ
 -  ⥬    ७ "bak".  室,
⮡ ᪫   ଠ樨, ᮤঠ襩
 室 䠩, ᫨    ४ it-㫥 
᫨ ࠡ ணࠬ  - 稭  㤥 
 .
    ணࠬ ஢, ⮡ ࠡ뢠 䠩 稭
 ᨬ "IMPM"; ᫨   ⠪, ,   it-,
  㢨 ᮮ饭 "Incorrect file format!".
    ணࠬ 頥 樮 ⥬  襭:
0 - ᯥ譮 襭, 1 - 訡. 饭  訡 ⠪
뢮  ࠭.
      浪    ⮫쪮 
 ୠ,   砫 祭 ࠬ  ஬
.


筨


1. ᠭ ଠ 㫥 Impulse Tracker (䠩 "ITTECH.TXT"
     ⠢ Impulse Tracker 2.14).




    㣨    ᮧ / ࠡ⪥ 㫥 Impulse
Tracker:

1. " Pro Tracker 3 -> Impulse Tracker". ". 
   " 12/2004.
