Ticket #7957: timidity.diff
File timidity.diff, 5.1 KB (added by , 23 years ago) |
---|
-
gameDetector.cpp
568 568 #if defined(UNIX) && !defined(__BEOS__) 569 569 case MD_SEQ: return MidiDriver_SEQ_create(); 570 570 #endif 571 #if defined(TIMIDITY) 572 case MD_TIMIDITY: return MidiDriver_TIMIDITY_create(); 573 #endif 571 574 #if defined(__APPLE__) 572 575 case MD_QTMUSIC: return MidiDriver_QT_create(); 573 576 case MD_COREAUDIO: return MidiDriver_CORE_create(); -
sound/mididrv.cpp
29 29 #include "stdafx.h" 30 30 #include "scumm.h" 31 31 #include "mididrv.h" 32 #if defined(TIMIDITY) 33 #include <sys/socket.h> 34 #include <netdb.h> 35 #endif 32 36 33 37 #if defined(WIN32) && !defined(_WIN32_WCE) 34 38 … … 786 790 787 791 788 792 789 #if 0790 793 791 /* Old code for timidity support, maybe somebody can rewrite this for the 792 new midi driver system? 793 */ 794 #if defined(TIMIDITY) 795 /* TIMIDITY driver */ 796 class MidiDriver_TIMIDITY : public MidiDriver { 797 public: 798 MidiDriver_TIMIDITY(); 799 int open(int mode); 800 int open_socket(int *socketptr, int port); 801 void close(); 802 void send(uint32 b); 803 void pause(bool pause); 804 void set_stream_callback(void *param, StreamCallback *sc); 805 private: 806 StreamCallback *_stream_proc; 807 void *_stream_param; 808 int _mode; 809 int device; 810 }; 811 812 MidiDriver_TIMIDITY::MidiDriver_TIMIDITY() { 813 _mode=0; 814 device=0; 815 } 794 816 795 817 796 /*********** Timidity */ 797 int MidiDriver::connect_to_timidity(int port) 818 int MidiDriver_TIMIDITY::open(int mode) 819 { 820 int s,s2,err; 821 int len; 822 int dummy,newport; 823 char buf[256]; 824 825 if (_mode != 0 ) 826 return MERR_ALREADY_OPEN; 827 device = 0; 828 _mode = mode; 829 if (mode!=MO_SIMPLE) return MERR_STREAMING_NOT_AVAILABLE; 830 831 if ((err = open_socket(&s,7777))!=0) 832 return err; 833 834 len = ::read(s, buf, 256); 835 sprintf(buf,"SETBUF %f %f\n",0.1,0.15); 836 write(s, buf, strlen(buf)); 837 838 len = ::read(s, buf, 256); 839 sprintf(buf,"OPEN lsb\n"); 840 write(s, buf, strlen(buf)); 841 842 len = ::read(s, buf, 256); 843 sscanf(buf,"%d %d",&dummy, &newport); 844 write(s, buf, strlen(buf)); 845 846 if ((err = open_socket(&s2,newport))!=0) 847 return err; 848 device = s2; 849 return 0; 850 } 851 852 int MidiDriver_TIMIDITY::open_socket(int *socketptr, int port) 798 853 { 799 854 int s = 0; 800 855 #if !defined(__APPLE__CW) && !defined(__MORPHOS__) // No socket support on Apple Carbon or Morphos … … 803 858 804 859 serverhost = gethostbyname("localhost"); 805 860 if (serverhost == NULL) 806 error("Could not resolve Timidity host ('localhost')"); 861 return MERR_CANNOT_CONNECT; 862 //warning("Could not resolve Timidity host ('localhost')"); 807 863 808 864 sadd.sin_family = serverhost->h_addrtype; 809 865 sadd.sin_port = htons(port); … … 811 867 812 868 s = socket(AF_INET, SOCK_STREAM, 0); 813 869 if (s < 0) 814 error("Could not open Timidity socket"); 870 return MERR_CANNOT_CONNECT; 871 //error("Could not open Timidity socket"); 815 872 816 873 if (connect(s, (struct sockaddr *)&sadd, sizeof(struct sockaddr_in)) < 0) 817 error("Could not connect to Timidity server"); 874 return MERR_CANNOT_CONNECT; 875 //error("Could not connect to Timidity server"); 876 *socketptr = s; 877 return 0; 818 878 #endif 819 return s;879 return MERR_DEVICE_NOT_AVAILABLE; 820 880 } 821 881 822 void MidiDriver ::midiInitTimidity()882 void MidiDriver_TIMIDITY::close() 823 883 { 824 int s, s2; 825 int len; 826 int dummy, newport; 827 char buf[256]; 884 ::close(device); 885 _mode = 0; 886 } 828 887 829 s = connect_to_timidity(7777); 830 len = read(s, buf, 256); // buf[len] = '\0'; printf("%s", buf); 831 sprintf(buf, "SETBUF %f %f\n", 0.1, 0.15); 832 write(s, buf, strlen(buf)); 833 len = read(s, buf, 256); // buf[len] = '\0'; printf("%s", buf); 888 void MidiDriver_TIMIDITY::send(uint32 b) 889 { 890 unsigned char buf[256]; 891 int position = 0; 834 892 835 sprintf(buf, "OPEN lsb\n"); 836 write(s, buf, strlen(buf)); 837 len = read(s, buf, 256); // buf[len] = '\0'; printf("%s", buf); 893 switch (b & 0xF0) { 894 case 0x80: 895 case 0x90: 896 case 0xA0: 897 case 0xB0: 898 case 0xE0: 899 buf[position++] = SEQ_MIDIPUTC; 900 buf[position++] = (unsigned char)b; 901 buf[position++] = DEVICE_NUM; 902 buf[position++] = 0; 903 buf[position++] = SEQ_MIDIPUTC; 904 buf[position++] = (unsigned char)((b >> 8) & 0x7F); 905 buf[position++] = DEVICE_NUM; 906 buf[position++] = 0; 907 buf[position++] = SEQ_MIDIPUTC; 908 buf[position++] = (unsigned char)((b >> 16) & 0x7F); 909 buf[position++] = DEVICE_NUM; 910 buf[position++] = 0; 911 break; 912 case 0xC0: 913 case 0xD0: 914 buf[position++] = SEQ_MIDIPUTC; 915 buf[position++] = (unsigned char)b; 916 buf[position++] = DEVICE_NUM; 917 buf[position++] = 0; 918 buf[position++] = SEQ_MIDIPUTC; 919 buf[position++] = (unsigned char)((b >> 8) & 0x7F); 920 buf[position++] = DEVICE_NUM; 921 buf[position++] = 0; 922 break; 923 default: 924 fprintf(stderr, "Unknown : %08x\n", (int) b); 925 break; 926 } 927 write(device, buf, position); 928 } 838 929 839 sscanf(buf, "%d %d", &dummy, &newport); 840 printf(" => port = %d\n", newport); 930 void MidiDriver_TIMIDITY::pause(bool pause) 931 { 932 debug(1,"pause: %d",pause); 933 if (_mode == MO_STREAMING) { 934 } 935 } 841 936 842 s2 = connect_to_timidity(newport); 843 _mo = (void *)s2; 937 void MidiDriver_TIMIDITY::set_stream_callback(void *param, StreamCallback *sc) 938 { 939 _stream_param = param; 940 _stream_proc = sc; 844 941 } 845 942 943 MidiDriver *MidiDriver_TIMIDITY_create() 944 { 945 return new MidiDriver_TIMIDITY(); 946 } 846 947 847 #endif /* 0*/948 #endif /* TIMIDITY */