[vConnect/trunk/stand2.0]
@@ -1,74 +0,0 @@ | ||
1 | -/* | |
2 | - * Connection.cpp | |
3 | - * | |
4 | - * Copyright (C) 2011 kbinani. | |
5 | - */ | |
6 | - | |
7 | -#include "Connection.h" | |
8 | - | |
9 | -namespace vcnctd | |
10 | -{ | |
11 | - Socket Connection::get( int number ) | |
12 | - { | |
13 | - if( number <= 0 ) | |
14 | - { | |
15 | - return mSockets[0]; | |
16 | - } | |
17 | - else | |
18 | - { | |
19 | - map<int, Socket>::iterator itr = mMap.find( number ); | |
20 | - if( itr != mMap.end() ) | |
21 | - { | |
22 | - int index = mMap[number]; | |
23 | - return mSockets[index]; | |
24 | - } | |
25 | - else | |
26 | - { | |
27 | - return NULL; | |
28 | - } | |
29 | - } | |
30 | - } | |
31 | - | |
32 | - void Connection::initSockets( Config *config ) | |
33 | - { | |
34 | - //int s[SOCK_MAX + 1]; /* array of socket descriptors */ | |
35 | - int max = 0; /* max num of used socket */ | |
36 | - int n = 0; | |
37 | - socklen_t len; | |
38 | - fd_set readfds; | |
39 | - int clilen; /* client length */ | |
40 | - struct sockaddr_in saddr; /* サーバ側(自分)のアドレス情報 */ | |
41 | - struct sockaddr_in caddr; /* クライアント側のアドレス情報を入れるところ */ | |
42 | - char str[1024]; /* string buffer */ | |
43 | - int i, j; /* loop counter */ | |
44 | - int msglen; | |
45 | - | |
46 | - /* | |
47 | - * ソケットを作る。 | |
48 | - * このソケットはINETドメインでストリーム型(コネクション型) 。 | |
49 | - */ | |
50 | - if( (mSockets[0] = socket( AF_INET, SOCK_STREAM, 0 )) == -1 ) | |
51 | - { | |
52 | - perror( "socket" ); | |
53 | - exit( 1 ); | |
54 | - } | |
55 | - | |
56 | - /* | |
57 | - * saddrの中身を0にしておかないと、bind()でエラーが起こることがある | |
58 | - */ | |
59 | - memset( (char *)&saddr, 0, sizeof( saddr ) ); | |
60 | - | |
61 | - /* ソケットに名前をつける bind() */ | |
62 | - saddr.sin_family = AF_INET; | |
63 | - saddr.sin_addr.s_addr = INADDR_ANY; | |
64 | - saddr.sin_port = htons( config->getPort() ); /* 定数PORTは#defineしたもの */ | |
65 | - | |
66 | - if( (bind( mSockets[0], (struct sockaddr *)&saddr, sizeof( saddr ) )) == -1 ) | |
67 | - { | |
68 | - perror( "bind" ); | |
69 | - exit( 1 ); | |
70 | - } | |
71 | - | |
72 | - } | |
73 | - | |
74 | -} |
@@ -1,71 +0,0 @@ | ||
1 | -/* | |
2 | - * Connection.h | |
3 | - * | |
4 | - * Copyright (C) 2011 kbinani. | |
5 | - */ | |
6 | -#ifndef __Connection_h__ | |
7 | -#define __Connection_h__ | |
8 | - | |
9 | -#ifdef __WIN32__ | |
10 | - #include <winsock2.h> | |
11 | - typedef int socklen_t; | |
12 | -#else | |
13 | - #include <netinet/in.h> | |
14 | - #include <sys/socket.h> | |
15 | - #include <sys/types.h> | |
16 | -#endif | |
17 | -#include <sys/time.h> /* selectシステムコール */ | |
18 | -#include <map> | |
19 | - | |
20 | -#include "Config.h" | |
21 | - | |
22 | -using namespace std; | |
23 | - | |
24 | -namespace vcnctd | |
25 | -{ | |
26 | - | |
27 | - typedef int Socket; | |
28 | - | |
29 | - /// <summary> | |
30 | - /// ソケット接続を管理します. | |
31 | - /// </summary> | |
32 | - class Connection | |
33 | - { | |
34 | - public: // public method | |
35 | - | |
36 | - /// <summary> | |
37 | - /// 第number番目に接続したクライアントとのソケット接続を取得します. | |
38 | - /// </summary> | |
39 | - /// <param name="number">クライアントとの接続番号</param> | |
40 | - /// <returns>ソケット接続</returns> | |
41 | - Socket get( int number ); | |
42 | - | |
43 | - /// <summary> | |
44 | - /// ソケットを用意します. | |
45 | - /// </summary> | |
46 | - void initSockets( Config *config ); | |
47 | - | |
48 | - public: // public static field | |
49 | - | |
50 | - /// <summary> | |
51 | - /// 許可する同時最大接続数. | |
52 | - /// </summary> | |
53 | - static const int MAX_CONS = 128; | |
54 | - | |
55 | - private: | |
56 | - | |
57 | - /// <summary> | |
58 | - /// ソケット接続のリスト. | |
59 | - /// </summary> | |
60 | - Socket mSockets[MAX_CONS]; | |
61 | - | |
62 | - /// <summary> | |
63 | - /// 接続番号とソケットリストのインデックスを紐付けるマップ. | |
64 | - /// </summary> | |
65 | - map<int, int> mMap; | |
66 | - | |
67 | - }; | |
68 | - | |
69 | -} | |
70 | - | |
71 | -#endif |
@@ -12,7 +12,6 @@ | ||
12 | 12 | { |
13 | 13 | this->synth = new Synth(); |
14 | 14 | this->config = new Config(); |
15 | - this->cons = new Connection(); | |
16 | 15 | } |
17 | 16 | |
18 | 17 | Server::~Server() |
@@ -28,121 +27,146 @@ | ||
28 | 27 | UtauDB::dbClear(); |
29 | 28 | } |
30 | 29 | |
31 | - void Server::startListening() | |
30 | + int Server::startListening() | |
32 | 31 | { |
33 | - // ソケット接続を初期化. | |
34 | - this->cons->initSockets( this->config ); | |
32 | + const int SOCK_MAX = 128; | |
33 | + | |
34 | + // ソケット接続のリスト | |
35 | + Socket s[SOCK_MAX + 1]; | |
36 | + for( int i = 0; i < SOCK_MAX + 1; i++ ) | |
37 | + { | |
38 | + s[i] = -1; | |
39 | + } | |
40 | + | |
41 | + // ソケット作る | |
42 | + if( (s[0] = socket( AF_INET, SOCK_STREAM, 0 )) == -1 ) | |
43 | + { | |
44 | + // エラーなので死ぬ | |
45 | + printf( "error; create first socket\n" ); | |
46 | + return 0; | |
47 | + } | |
35 | 48 | |
36 | - /* 接続されるのを待つ listen() */ | |
37 | - /* 第2引数の値を大きくする */ | |
38 | - if( (listen( this->cons->get( 0 ), MAX_SOCKETS )) == -1 ) | |
49 | + // サーバーのアドレス情報 | |
50 | + struct sockaddr_in server_addr; | |
51 | + memset( (char *)&server_addr, 0, sizeof( server_addr ) ); | |
52 | + server_addr.sin_family = AF_INET; | |
53 | + server_addr.sin_addr.s_addr = INADDR_ANY; | |
54 | + server_addr.sin_port = htons( this->config->getPort() ); | |
55 | + | |
56 | + // ソケットとアドレスを紐付け | |
57 | + if( (bind( s[0], (struct sockaddr *)&server_addr, sizeof( server_addr ) )) == -1 ) | |
39 | 58 | { |
40 | - perror( "listen" ); | |
41 | - exit( 1 ); | |
42 | - } | |
43 | - max = 1; /* s[0] is ready */ | |
59 | + // 紐付けに失敗したので死ぬ | |
60 | + printf( "error; bind first socket\n" ); | |
61 | + return 0; | |
62 | + } | |
44 | 63 | |
45 | - /* メインループ */ | |
64 | + // サーバーのソケットを接続待ち | |
65 | + if( (listen( s[0], SOCK_MAX )) == -1 ) | |
66 | + { | |
67 | + // 待受開始に失敗したので死ぬ | |
68 | + printf( "error; listen first socket\n" ); | |
69 | + return 0; | |
70 | + } | |
71 | + | |
72 | + // 受信メッセージ用の文字列 | |
73 | + char str[1024]; | |
74 | + | |
75 | + // メインループ.無限ループ | |
46 | 76 | while( 1 ) |
47 | 77 | { |
48 | - FD_ZERO( &readfds ); /* fdsの初期化 */ | |
49 | - printf( "max: %d\n", max ); | |
50 | - /* | |
51 | - * すでにクライアントと接続されているソケットのビットを | |
52 | - * セットしてselect()の検査対象にする。 | |
53 | - */ | |
54 | - for( i = 0; i < max; i++ ) | |
78 | + fd_set readfds; | |
79 | + FD_ZERO( &readfds ); | |
80 | + | |
81 | + // 接続済みのクライアントのビットを立てる | |
82 | + for( int i = 0; i < SOCK_MAX + 1; i++ ) | |
55 | 83 | { |
56 | - if( mSockets[i] != UNUSED ) | |
57 | - { | |
58 | - FD_SET( mSockets[i], &readfds ); | |
59 | - } | |
84 | + if( s[i] <= 0 ) continue; | |
85 | + FD_SET( s[i], &readfds ); | |
60 | 86 | } |
61 | - /* | |
62 | - * メッセージが到着しているソケットがないか調べる | |
63 | - */ | |
87 | + | |
88 | + // メッセージの到着をチェック | |
89 | + int n; | |
64 | 90 | if( (n = select( FD_SETSIZE, &readfds, NULL, NULL, NULL )) == -1 ) |
65 | 91 | { |
66 | - perror( "select" ); | |
67 | - exit( 1 ); | |
92 | + printf( "error; select failed\n" ); | |
93 | + return 0; | |
68 | 94 | } |
69 | - printf( "select returns: %d\n", n ); | |
70 | - /* | |
71 | - * 1~maxのソケットに届くのは、すでに接続されているクライアントからの | |
72 | - * メッセージである。 | |
73 | - * もしメッセージがあれば、接続されているすべてのクライアントに送る。 | |
74 | - */ | |
75 | - for( i = 1; i < max; i++ ) | |
95 | + | |
96 | + // 接続済みソケットからのメッセージをチェック | |
97 | + for( int i = 1; i < SOCK_MAX + 1; i++ ) | |
76 | 98 | { |
77 | - if( mSockets[i] != UNUSED ) | |
99 | + // 接続済み? | |
100 | + if( s[i] <= 0 ) continue; | |
101 | + // メッセージ到着している? | |
102 | + if( !FD_ISSET( s[i], &readfds ) ) continue; | |
103 | + | |
104 | + strcpy( str, "" ); | |
105 | + int msg_length = read( s[i], str, sizeof( str ) ); | |
106 | + if( msg_length < 0 ) | |
78 | 107 | { |
79 | - if( FD_ISSET( mSockets[i], &readfds ) ) | |
80 | - { | |
81 | - /* | |
82 | - * mSockets[i]のビットが立っていれば、mSockets[i]にメッセージが到着している | |
83 | - */ | |
84 | - printf( "s[%d] ready for reading\n", i ); | |
85 | - if( (msglen = read( mSockets[i], str, sizeof( str ) )) == -1 ) | |
86 | - { | |
87 | - /* 受信失敗 */ | |
88 | - perror("read"); | |
89 | - } | |
90 | - else if ( msglen != 0 ) | |
91 | - { | |
92 | - /* メッセージの受信に成功 */ | |
93 | - printf( "client[%d]: %s", i, str ); | |
94 | - //Modification(str,msglen); /* 作業 */ | |
95 | - /* 接続されているクライアントすべてにメッセージを送る */ | |
96 | - for( j = 1; j < max; j++ ) | |
97 | - { | |
98 | - if( mSockets[j] != UNUSED ) | |
99 | - { | |
100 | - write( mSockets[j], str, strlen( str ) ); | |
101 | - } | |
102 | - } | |
103 | - } | |
104 | - else | |
105 | - { | |
106 | - printf( "client[%d]: connection closed.\n", i ); | |
107 | - close( mSockets[i] ); | |
108 | - mSockets[i] = UNUSED; | |
109 | - } | |
110 | - } | |
108 | + // 受信に失敗 | |
109 | + printf( "warning; read failed from #%d\n", i ); | |
111 | 110 | } |
112 | - } | |
113 | - /* | |
114 | - * 新たな接続要求があった場合は、s[0]のビットが立つ。 | |
115 | - * 以下では新たな接続の受け付けを行う。 | |
116 | - */ | |
117 | - if( FD_ISSET( mSockets[0], &readfds ) != 0 ) | |
111 | + else if( msg_length > 0 ) | |
112 | + { | |
113 | + // 受信に成功 | |
114 | + string s_str = str; | |
115 | + int indx = s_str.find( "\n" ); | |
116 | + if( indx > 0 ) s_str = s_str.substr( 0, indx ); | |
117 | + printf( "info; #%d said \"%s\"\n", i, s_str.c_str() ); | |
118 | + char msg[] = "[OK]"; | |
119 | + write( s[i], (char *)msg, strlen( msg ) ); | |
120 | + } | |
121 | + else | |
122 | + { | |
123 | + // 接続が切られた | |
124 | + printf( "info; %d disconnected\n", i ); | |
125 | + close( s[i] ); | |
126 | + s[i] = 0; | |
127 | + } | |
128 | + } | |
129 | + | |
130 | + // 新しい接続がないかな | |
131 | + if( FD_ISSET( s[0], &readfds ) != 0 ) | |
118 | 132 | { |
119 | - printf( "Accept New one.\n" ); | |
120 | - /* 接続を確立する accept() */ | |
121 | - len = sizeof( caddr ); | |
122 | - mSockets[max] = | |
123 | - accept( mSockets[0], (struct sockaddr *)&caddr, &len ); | |
124 | - printf( "%d = accept()\n", mSockets[max] ); | |
125 | - if( mSockets[max] == -1 ) | |
133 | + printf( "info; new connection\n" ); | |
134 | + | |
135 | + struct sockaddr_in client_addr; | |
136 | + socklen_t len = sizeof( client_addr ); | |
137 | + | |
138 | + // どれがあいてるかな | |
139 | + int index = -1; | |
140 | + for( int i = 1; i < SOCK_MAX + 1; i++ ) | |
126 | 141 | { |
127 | - perror( NULL ); | |
128 | - exit( 1 ); | |
142 | + if( s[i] <= 0 ) | |
143 | + { | |
144 | + index = i; | |
145 | + break; | |
146 | + } | |
129 | 147 | } |
130 | - if( max < MAX_SOCKETS ) | |
148 | + if( index < 0 ) | |
131 | 149 | { |
132 | - printf( "client accepted(%d).\n", max ); | |
133 | - max++; | |
150 | + // 最大接続数をオーバーしてる | |
151 | + printf( "warning: server too busy\n" ); | |
134 | 152 | } |
135 | 153 | else |
136 | 154 | { |
137 | - printf( "refuse connection.\n" ); | |
138 | - strcpy( str, "Server is too busy.\n" ); | |
139 | - write( mSockets[max], str, strlen( str ) ); | |
140 | - close( mSockets[max] ); | |
155 | + s[index] = accept( s[0], (struct sockaddr *)&client_addr, &len ); | |
156 | + if( s[index] == -1 ) | |
157 | + { | |
158 | + printf( "error; accept failed\n" ); | |
159 | + return 0; | |
160 | + } | |
161 | + else | |
162 | + { | |
163 | + printf( "info; #%d connection accepted\n", index ); | |
164 | + } | |
141 | 165 | } |
142 | 166 | } |
143 | 167 | } |
144 | 168 | } |
145 | - | |
169 | + | |
146 | 170 | void Server::analyze() |
147 | 171 | { |
148 | 172 | runtimeOptions opts; |
@@ -6,6 +6,10 @@ | ||
6 | 6 | #ifndef __Server_h__ |
7 | 7 | #define __Server_h__ |
8 | 8 | |
9 | +#include <netinet/in.h> | |
10 | +#include <sys/socket.h> | |
11 | +#include <sys/types.h> | |
12 | +#include <sys/time.h> | |
9 | 13 | #include <fcntl.h> |
10 | 14 | #include <stdio.h> |
11 | 15 | #include <string.h> |
@@ -15,8 +19,8 @@ | ||
15 | 19 | #define MAX_SOCKETS 5 /* 最大ソケット数をここで決めた (最大32)*/ |
16 | 20 | #define UNUSED (-1) |
17 | 21 | |
22 | +#include "../stand/vsqMetaText/Socket.h" | |
18 | 23 | #include "Config.h" |
19 | -#include "Connection.h" | |
20 | 24 | #include "vcnctd.h" |
21 | 25 | |
22 | 26 | using namespace vcnctd; |
@@ -44,7 +48,7 @@ | ||
44 | 48 | /// <summary> |
45 | 49 | /// ポートのLISTENを開始します. |
46 | 50 | /// </summary> |
47 | - void startListening(); | |
51 | + int startListening(); | |
48 | 52 | |
49 | 53 | /// <summary> |
50 | 54 | /// 未解析の音源について,解析を行います. |
@@ -53,13 +57,8 @@ | ||
53 | 57 | |
54 | 58 | |
55 | 59 | public: |
56 | - | |
60 | + | |
57 | 61 | /// <summary> |
58 | - /// ソケット接続を管理するインスタンス. | |
59 | - /// </summary> | |
60 | - Connection *cons; | |
61 | - | |
62 | - /// <summary> | |
63 | 62 | /// 合成器のインスタンスです. |
64 | 63 | /// </summary> |
65 | 64 | Synth *synth; |
@@ -77,6 +76,7 @@ | ||
77 | 76 | /// </summary> |
78 | 77 | vector<CorpusManager *> mCorpusManagers; |
79 | 78 | |
79 | + int mMax; | |
80 | 80 | /// <summary> |
81 | 81 | /// ソケットのリスト |
82 | 82 | /// </summary> |
@@ -1,9 +1,9 @@ | ||
1 | 1 | SRC=vcnctd.cpp \ |
2 | - Connection.cpp \ | |
3 | 2 | Server.cpp \ |
4 | 3 | Config.cpp \ |
5 | 4 | ConfDB.cpp \ |
6 | 5 | daemon.c \ |
6 | + ../stand/vsqMetaText/TextReader.cpp \ | |
7 | 7 | ../stand/corpusManager.cpp \ |
8 | 8 | ../stand/matching.cpp \ |
9 | 9 | ../stand/mb_text.cpp \ |
@@ -33,10 +33,10 @@ | ||
33 | 33 | ../stand/world/synthesis_v4.cpp |
34 | 34 | |
35 | 35 | HDR=Server.h \ |
36 | - Connection.h \ | |
37 | 36 | Config.h \ |
38 | 37 | daemon.h \ |
39 | 38 | ConfDB.h \ |
39 | + ../stand/vsqMetaText/TextReader.h \ | |
40 | 40 | ../stand/mb_text.h \ |
41 | 41 | ../stand/vConnect.h \ |
42 | 42 | ../stand/standData.h \ |
@@ -26,6 +26,12 @@ | ||
26 | 26 | objectMap.insert( make_pair( temp, (vsqBase *)&voiceDataBase ) ); |
27 | 27 | } |
28 | 28 | |
29 | +bool vsqFileEx::read( Socket socket, runtimeOptions options ) | |
30 | +{ | |
31 | + MB_FILE *fp = mb_fopen( (int)socket, options.encodingVsqText.c_str() ); | |
32 | + return readCore( fp ); | |
33 | +} | |
34 | + | |
29 | 35 | bool vsqFileEx::read( string_t file_name, runtimeOptions options ) |
30 | 36 | { |
31 | 37 | #ifdef _DEBUG |
@@ -44,75 +50,74 @@ | ||
44 | 50 | cout << "vsqFileEx::readVsqFile; (fp==NULL)=" << (fp == NULL ? "true" : "false") << endl; |
45 | 51 | #endif |
46 | 52 | |
47 | - if( fp ) | |
53 | + return readCore( fp ); | |
54 | +} | |
55 | + | |
56 | +bool vsqFileEx::readCore( MB_FILE *fp ) | |
57 | +{ | |
58 | + if( !fp ) return false; | |
59 | + | |
60 | + string_t temp, search, left, right; | |
61 | + map_t<string_t, vsqBase *>::iterator i; | |
62 | + | |
63 | + while( mb_fgets( temp, fp ) ) | |
48 | 64 | { |
49 | - string_t temp, search, left, right; | |
50 | - map_t<string_t, vsqBase *>::iterator i; | |
51 | - | |
52 | - while( mb_fgets( temp, fp ) ) | |
53 | - { | |
54 | 65 | #ifdef _DEBUG |
55 | - string s; | |
56 | - mb_conv( temp, s ); | |
57 | - cout << "vsqFileEx::readVsqFile; temp=" << s << endl; | |
66 | + string s; | |
67 | + mb_conv( temp, s ); | |
68 | + cout << "vsqFileEx::readVsqFile; temp=" << s << endl; | |
58 | 69 | #endif |
59 | - if( temp.find( _T("[") ) == 0 ) | |
70 | + if( temp.find( _T("[") ) == 0 ) | |
71 | + { | |
72 | + search = temp; | |
73 | + continue; | |
74 | + } | |
75 | + string_t::size_type indx_equal = temp.find( _T("=") ); | |
76 | + if( indx_equal == string_t::npos ) | |
77 | + { | |
78 | + left = temp; | |
79 | + right = _T(""); | |
80 | + } | |
81 | + else | |
82 | + { | |
83 | + left = temp.substr( 0, indx_equal ); | |
84 | + right = temp.substr( indx_equal + 1 ); | |
85 | + } | |
86 | + i = objectMap.find( search ); | |
87 | + if( i != objectMap.end() ) | |
88 | + { | |
89 | + if( i->second ) | |
60 | 90 | { |
61 | - search = temp; | |
62 | - continue; | |
63 | - } | |
64 | - string_t::size_type indx_equal = temp.find( _T("=") ); | |
65 | - if( indx_equal == string_t::npos ) | |
66 | - { | |
67 | - left = temp; | |
68 | - right = _T(""); | |
69 | - } | |
70 | - else | |
71 | - { | |
72 | - left = temp.substr( 0, indx_equal ); | |
73 | - right = temp.substr( indx_equal + 1 ); | |
74 | - } | |
75 | - i = objectMap.find( search ); | |
76 | - if( i != objectMap.end() ) | |
77 | - { | |
78 | - if( i->second ) | |
91 | + if( search.compare( _T("[EventList]") ) == 0 ) | |
79 | 92 | { |
80 | - if( search.compare( _T("[EventList]") ) == 0 ) | |
93 | + string_t::size_type indx_comma = right.find( _T(",") ); | |
94 | + while( indx_comma != string_t::npos ) | |
81 | 95 | { |
82 | - string_t::size_type indx_comma = right.find( _T(",") ); | |
83 | - while( indx_comma != string_t::npos ) | |
84 | - { | |
85 | - // コンマが見つからなくなるまでループ | |
86 | - string_t tright = right.substr( 0, indx_comma ); | |
87 | - i->second->setParameter( left, tright ); | |
88 | - right = right.substr( indx_comma + 1 ); | |
89 | - indx_comma = right.find( _T(",") ); | |
90 | - } | |
96 | + // コンマが見つからなくなるまでループ | |
97 | + string_t tright = right.substr( 0, indx_comma ); | |
98 | + i->second->setParameter( left, tright ); | |
99 | + right = right.substr( indx_comma + 1 ); | |
100 | + indx_comma = right.find( _T(",") ); | |
91 | 101 | } |
92 | - i->second->setParameter( left, right ); | |
93 | 102 | } |
103 | + i->second->setParameter( left, right ); | |
94 | 104 | } |
95 | - else | |
96 | - { | |
97 | - string message; | |
98 | - string t_search; | |
99 | - mb_conv( search, t_search ); | |
100 | - message = "vsqFileEx::readVsqFile; not found: " + t_search; | |
101 | - outputError( message.c_str() ); | |
102 | - } | |
103 | 105 | } |
104 | - mb_fclose( fp ); | |
106 | + else | |
107 | + { | |
108 | + string message; | |
109 | + string t_search; | |
110 | + mb_conv( search, t_search ); | |
111 | + message = "vsqFileEx::readVsqFile; not found: " + t_search; | |
112 | + outputError( message.c_str() ); | |
113 | + } | |
114 | + } | |
115 | + mb_fclose( fp ); | |
105 | 116 | |
106 | - // utau音源が無ければ合成しようがないので false. | |
107 | - int size = UtauDB::dbSize(); | |
108 | - result = (size > 0); | |
109 | - } | |
110 | -#ifdef _DEBUG | |
111 | - cout << "type any key to continue..."; | |
112 | - int i; | |
113 | - scanf( "%d", &i ); | |
114 | -#endif | |
115 | - return result; | |
117 | + // utau音源が無ければ合成しようがないので false. | |
118 | + int size = UtauDB::dbSize(); | |
119 | + | |
120 | + return (size > 0); | |
116 | 121 | } |
117 | 122 | |
118 | 123 | double vsqFileEx::getEndSec() |
@@ -0,0 +1,66 @@ | ||
1 | +/** | |
2 | + * TextReader.cpp | |
3 | + * | |
4 | + * Copyright (C) 2011 kbinani. | |
5 | + */ | |
6 | +#include "TextReader.h" | |
7 | + | |
8 | +TextReader::TextReader( MB_FILE *fp ) | |
9 | +{ | |
10 | + this->mFile = fp; | |
11 | + this->mSocket = 0; | |
12 | +} | |
13 | + | |
14 | +TextReader::TextReader( Socket socket ) | |
15 | +{ | |
16 | + this->mFile = 0; | |
17 | + this->mSocket = socket; | |
18 | +} | |
19 | + | |
20 | +TextReader::~TextReader() | |
21 | +{ | |
22 | + this->mFile = 0; | |
23 | + this->mSocket = 0; | |
24 | +} | |
25 | + | |
26 | +int TextReader::getNextLine( string &buffer ) | |
27 | +{ | |
28 | + buffer = ""; | |
29 | + if( 0 == mFile ) return -1; | |
30 | + if( 0 == mSocket ) return -1; | |
31 | + if( mFile ) | |
32 | + { | |
33 | + if( mb_fgets( buffer, mFile ) ) | |
34 | + { | |
35 | + return 0; | |
36 | + } | |
37 | + else | |
38 | + { | |
39 | + return -1; | |
40 | + } | |
41 | + } | |
42 | + else | |
43 | + { | |
44 | + } | |
45 | +} | |
46 | + | |
47 | +int TextReader::getNextLine( wstring &buffer ) | |
48 | +{ | |
49 | + buffer = L""; | |
50 | + if( 0 == mFile ) return -1; | |
51 | + if( 0 == mSocket ) return -1; | |
52 | + if( mFile ) | |
53 | + { | |
54 | + if( mb_fgets( buffer, mFile ) ) | |
55 | + { | |
56 | + return 0; | |
57 | + } | |
58 | + else | |
59 | + { | |
60 | + return -1; | |
61 | + } | |
62 | + } | |
63 | + else | |
64 | + { | |
65 | + } | |
66 | +} |
@@ -11,6 +11,7 @@ | ||
11 | 11 | #include "vsqTempo.h" |
12 | 12 | #include "vsqPhonemeDB.h" |
13 | 13 | #include "../runtimeOptions.h" |
14 | +#include "Socket.h" | |
14 | 15 | |
15 | 16 | /// <summary> |
16 | 17 | /// VSQメタテキストが表現するシーケンスを取り扱うクラスです. |
@@ -24,7 +25,7 @@ | ||
24 | 25 | vsqFileEx(); |
25 | 26 | |
26 | 27 | /// <summary> |
27 | - /// VSQのメタテキストを読み込みます. | |
28 | + /// ファイルからVSQのメタテキストを読み込みます. | |
28 | 29 | /// </summary> |
29 | 30 | /// <param name="file_name">読み込むメタテキストファイルのパス.</param> |
30 | 31 | /// <param name="options">読み込み時の設定値.</param> |
@@ -32,6 +33,14 @@ | ||
32 | 33 | bool read( string_t file_name, runtimeOptions options ); |
33 | 34 | |
34 | 35 | /// <summary> |
36 | + /// ソケットからVSQのメタテキストを読み込みます. | |
37 | + /// </summary> | |
38 | + /// <param name="socket">読み込むソケット.</param> | |
39 | + /// <param name="options">読み込み時の設定値.</param> | |
40 | + /// <returns>読み込みに成功した場合true,それ以外はfalseを返します.</returns> | |
41 | + bool read( Socket socket, runtimeOptions options ); | |
42 | + | |
43 | + /// <summary> | |
35 | 44 | /// シーケンスの演奏長さを取得します.単位は秒です. |
36 | 45 | /// </summary> |
37 | 46 | /// <returns>シーケンスの演奏長さ.</returns> |
@@ -62,6 +71,14 @@ | ||
62 | 71 | protected: |
63 | 72 | |
64 | 73 | private: |
74 | + | |
75 | + /// <summary> | |
76 | + /// VSQのメタテキストを読み込みます. | |
77 | + /// </summary> | |
78 | + /// <param name="fp">読み込むストリーム.</param> | |
79 | + /// <returns>読み込みに成功した場合true,それ以外はfalseを返します.</returns> | |
80 | + bool readCore( MB_FILE *fp ); | |
81 | + | |
65 | 82 | vsqPhonemeDB voiceDataBase; |
66 | 83 | }; |
67 | 84 |
@@ -0,0 +1,69 @@ | ||
1 | +/** | |
2 | + * TextReader.h | |
3 | + * | |
4 | + * Copyright (C) 2011 kbinani. | |
5 | + */ | |
6 | +#ifndef __TextReader_h__ | |
7 | +#define __TextReader_h__ | |
8 | + | |
9 | +#include "../mb_text.h" | |
10 | +#include "Socket.h"; | |
11 | + | |
12 | +/// <summary> | |
13 | +/// ファイルまたはウェブソケットから1行ずつデータを読み込む機能を提供します. | |
14 | +/// </summary> | |
15 | +class TextReader | |
16 | +{ | |
17 | +public: | |
18 | + | |
19 | + /// <summary> | |
20 | + /// コンストラクタ.ファイルから読み込みます. | |
21 | + /// </summary> | |
22 | + /// <param name="fp">読み込むファイルのポインタ</param> | |
23 | + TextReader( MB_FILE *fp ); | |
24 | + | |
25 | + /// <summary> | |
26 | + /// コンストラクタ.ウェブソケットから読み込みます. | |
27 | + /// </summary> | |
28 | + /// <param name="socket">読み込むソケット接続</param> | |
29 | + TextReader( Socket socket ); | |
30 | + | |
31 | + /// <summary> | |
32 | + /// デストラクタ.ファイルやソケットのclose処理は行いません. | |
33 | + /// </summary> | |
34 | + ~TextReader(); | |
35 | + | |
36 | + /// <summary> | |
37 | + /// 次の行を取得します. | |
38 | + /// </summary> | |
39 | + /// <param name="buffer">行データの格納先</param> | |
40 | + /// <returns>読み込みに失敗した場合0,それ以外は0でない値を返します.</returns> | |
41 | + int getNextLine( wstring &buffer ); | |
42 | + | |
43 | + /// <summary> | |
44 | + /// 次の行を取得します. | |
45 | + /// </summary> | |
46 | + /// <param name="buffer">行データの格納先</param> | |
47 | + /// <returns>読み込みに失敗した場合0,それ以外は0でない値を返します.</returns> | |
48 | + int getNextLine( string &buffer ); | |
49 | + | |
50 | +private: | |
51 | + | |
52 | + TextReader(); | |
53 | + | |
54 | + | |
55 | +private: | |
56 | + | |
57 | + /// <summary> | |
58 | + /// ファイルのポインタ. | |
59 | + /// </summary> | |
60 | + MB_FILE *mFile; | |
61 | + | |
62 | + /// <summary> | |
63 | + /// ソケット接続 | |
64 | + /// </summary> | |
65 | + Socket mSocket; | |
66 | + | |
67 | +}; | |
68 | + | |
69 | +#endif |
@@ -0,0 +1,11 @@ | ||
1 | +/** | |
2 | + * Socket.h | |
3 | + * | |
4 | + * Copyright (C) 2011 kbinani. | |
5 | + */ | |
6 | +#ifndef __Socket_h__ | |
7 | +#define __Socket_h__ | |
8 | + | |
9 | +typedef int Socket; | |
10 | + | |
11 | +#endif |
@@ -95,6 +95,9 @@ | ||
95 | 95 | MB_CODEPAGE_DESCRIPTER descripter_for_char; |
96 | 96 | FILE *file; |
97 | 97 | int unit_len; |
98 | + int socket; | |
99 | + // シークして戻る操作を行った時の,バッファとして保持しておく文字 | |
100 | + char *charbuf; | |
98 | 101 | } MB_FILE; |
99 | 102 | |
100 | 103 | /** |
@@ -137,11 +140,18 @@ | ||
137 | 140 | */ |
138 | 141 | MB_FILE *mb_fopen( wstring file_name, const char *codepage ); |
139 | 142 | |
143 | +/// <summary> | |
144 | +/// 指定したコードページを使って,ソケットを読み込む | |
145 | +/// </summary> | |
146 | +MB_FILE *mb_fopen( int socket, const char *codepage ); | |
147 | + | |
140 | 148 | /** |
141 | 149 | * ファイルを閉じる |
142 | 150 | */ |
143 | 151 | int mb_fclose( MB_FILE *fp ); |
144 | 152 | |
153 | + | |
154 | + | |
145 | 155 | /** |
146 | 156 | * 内部関数 |
147 | 157 | * マルチバイト文字列が、指定したコードの制御文字を表すかどうかを調べます |
@@ -37,7 +37,9 @@ | ||
37 | 37 | { |
38 | 38 | for( unsigned int i = 0; i < UtauDB::mDBs.size(); i++ ) |
39 | 39 | { |
40 | - SAFE_DELETE( UtauDB::mDBs[i] ); | |
40 | + UtauDB *db = UtauDB::mDBs[i]; | |
41 | + UtauDB::mDBs[i] = NULL; | |
42 | + if( db ) delete db; | |
41 | 43 | } |
42 | 44 | UtauDB::mDBs.clear(); |
43 | 45 | } |
@@ -54,29 +56,29 @@ | ||
54 | 56 | } |
55 | 57 | } |
56 | 58 | |
59 | +// TODO: 読み込みが成功したとき0以外の値,失敗したとき0を返すように変更したい. | |
57 | 60 | int UtauDB::read( string_t path_oto_ini, const char *codepage ) |
58 | 61 | { |
59 | 62 | int result = 2; |
60 | 63 | MB_FILE *fp; |
61 | - //char buf[LINEBUFF_LEN]; | |
62 | 64 | string_t temp; |
63 | 65 | int index; |
64 | 66 | #ifdef _DEBUG |
65 | 67 | string s2; |
66 | 68 | mb_conv( fileName, s2 ); |
67 | - cout << "utauVoiceDataBase::readUtauVoiceDataBase; before normalize; path_oto_ini=" << s2 << endl; | |
69 | + cout << "UtauDB::read; before normalize; path_oto_ini=" << s2 << endl; | |
68 | 70 | #endif |
69 | 71 | normalize_path_separator( path_oto_ini ); |
70 | 72 | #ifdef _DEBUG |
71 | 73 | string s; |
72 | 74 | mb_conv( fileName, s ); |
73 | - cout << "utauVoiceDataBase::readUtauVoiceDataBase; after normalize; path_oto_ini=" << s << endl; | |
75 | + cout << "UtauDB::read; after normalize; path_oto_ini=" << s << endl; | |
74 | 76 | #endif |
75 | 77 | |
76 | 78 | fp = mb_fopen( path_oto_ini, codepage ); |
77 | 79 | |
78 | 80 | #ifdef _DEBUG |
79 | - cout << "utauVoiceDataBase::readUtauVoiceDataBase; (fp==NULL)=" << (fp == NULL ? "true" : "false") << endl; | |
81 | + cout << "UtauDB::read; (fp==NULL)=" << (fp == NULL ? "true" : "false") << endl; | |
80 | 82 | #endif |
81 | 83 | if( fp ) |
82 | 84 | { |
@@ -85,11 +87,11 @@ | ||
85 | 87 | while( mb_fgets( temp, fp ) ) |
86 | 88 | { |
87 | 89 | #ifdef _DEBUG |
88 | - string ts; | |
89 | - mb_conv( temp, ts ); | |
90 | - //cout << "utauVoiceDataBase::readUtauVoiceDataBase; temp=" << ts << endl; | |
90 | + string t_temp; | |
91 | + mb_conv( temp, t_temp ); | |
92 | + cout << "UtauDB::read; t_temp=" << t_temp << endl; | |
91 | 93 | #endif |
92 | - utauParameters* current = new utauParameters; | |
94 | + utauParameters *current = new utauParameters; | |
93 | 95 | if( current ) |
94 | 96 | { |
95 | 97 | if( ( index = temp.find( _T(".wav") ) ) == string_t::npos ) |
@@ -111,7 +113,8 @@ | ||
111 | 113 | else |
112 | 114 | { |
113 | 115 | current->lyric = temp.substr( temp.find( _T("=") ) + 1 ); |
114 | - current->lyric = current->lyric.substr( 0, current->lyric.find( _T(",") ) ); | |
116 | + current->lyric = | |
117 | + current->lyric.substr( 0, current->lyric.find( _T(",") ) ); | |
115 | 118 | } |
116 | 119 | |
117 | 120 | string t; |
@@ -160,7 +163,7 @@ | ||
160 | 163 | |
161 | 164 | int UtauDB::getParams( utauParameters ¶meters, string_t search ) |
162 | 165 | { |
163 | - int result = 0; | |
166 | + int result = 0; | |
164 | 167 | map_t<string_t, utauParameters *>::iterator i = mSettingMap.find( search ); |
165 | 168 | if( i != mSettingMap.end() ) |
166 | 169 | { |
@@ -25,6 +25,7 @@ | ||
25 | 25 | /// </summary> |
26 | 26 | /// <param name="path_oto_ini">oto.iniファイルのパス.</param> |
27 | 27 | /// <param name="codepage">oto.iniファイルのテキスト・エンコーディング.</param> |
28 | + /// <returns> | |
28 | 29 | int read( string_t fileName, const char *codepage ); |
29 | 30 | |
30 | 31 | /// <summary> |
@@ -48,8 +49,16 @@ | ||
48 | 49 | /// <returns>音素の数が0の場合trueを,そうでない場合はfalseを返します.</returns> |
49 | 50 | bool empty(); |
50 | 51 | |
52 | + /// <summary> | |
53 | + /// 音素とパラメータの紐付けを格納したマップの反復子の先頭を返します. | |
54 | + /// </summary> | |
55 | + /// <returns>反復子の先頭.</returns> | |
51 | 56 | map_t<string_t, utauParameters *>::iterator begin(); |
52 | - | |
57 | + | |
58 | + /// <summary> | |
59 | + /// 音素とパラメータの紐付けを格納したマップの反復子の末尾を返します. | |
60 | + /// </summary> | |
61 | + /// <returns>反復子の末尾.</returns> | |
53 | 62 | map_t<string_t, utauParameters *>::iterator end(); |
54 | 63 | |
55 | 64 | public: // public static method |
@@ -86,8 +95,14 @@ | ||
86 | 95 | /// </summary> |
87 | 96 | string_t mDBPath; |
88 | 97 | |
98 | + /// <summary> | |
99 | + /// 音素と音素のパラメータの紐付けを格納するマップ. | |
100 | + /// </summary> | |
89 | 101 | map_t<string_t, utauParameters *> mSettingMap; |
90 | 102 | |
103 | + /// <summary> | |
104 | + /// 音素のパラメータを格納したインスタンスのリスト. | |
105 | + /// </summary> | |
91 | 106 | list<utauParameters *> mSettingList; |
92 | 107 | |
93 | 108 |
@@ -271,37 +271,20 @@ | ||
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
274 | -/** | |
275 | - * 指定したコードページを使って、読込み専用のテキストファイルを開く。 | |
276 | - * MB_FILEから1行ずつ読み込むのは多重定義されたmb_fgetsを使うが、 | |
277 | - * mb_fgets( wstring &line, MB_FILE *fp )のほうは指定したコードページで、 | |
278 | - * mb_fgets( string &line, MB_FILE *fp )のほうはコードページを無視して読み込む。 | |
279 | - * | |
280 | - * @param file_name ファイルの名前 | |
281 | - * @param codepage コードページ | |
282 | - * @returns ファイル記述子 | |
283 | - */ | |
284 | -MB_FILE *mb_fopen( const char *file_name, const char *codepage ){ | |
285 | - mb_init(); | |
286 | - MB_FILE *fp = (MB_FILE *)malloc( sizeof( MB_FILE ) ); | |
287 | -#ifdef __GNUC__ | |
288 | - fp->file = fopen( file_name, "rb" ); | |
289 | -#else | |
290 | - fopen_s( &(fp->file), file_name, "rb" ); | |
291 | -#endif | |
292 | - if( !(fp->file) ){ | |
293 | -#ifdef _DEBUG | |
294 | - cout << "::mb_fopen; fopen failed; file_name=" << file_name << endl; | |
295 | -#endif | |
296 | - free( fp ); | |
297 | - return NULL; | |
298 | - } | |
274 | +/// <summary> | |
275 | +/// マルチバイト変換用のデスクリプタの初期化を行います. | |
276 | +/// </summary> | |
277 | +/// <param name="fp">初期化を行う対象となるファイルポインタ</param> | |
278 | +/// <param name="codepage">コードページの名前</param> | |
279 | +void mb_init_descriptor( MB_FILE *fp, const char *codepage ) | |
280 | +{ | |
299 | 281 | fp->unit_len = mb_unitlen_from_charset_name( codepage ); |
300 | 282 | if( fp->unit_len < 1 ){ |
301 | 283 | fp->unit_len = 1; |
302 | 284 | } |
285 | + fp->charbuf = (char *)malloc( fp->unit_len * sizeof( char ) ); | |
303 | 286 | #ifdef _DEBUG |
304 | - cout << "::mb_fopen; fp->unit_len=" << fp->unit_len << endl; | |
287 | + cout << "::mb_init_descriptor; fp->unit_len=" << fp->unit_len << endl; | |
305 | 288 | #endif |
306 | 289 | #ifdef MB_USE_ICONV |
307 | 290 | fp->descripter_for_wchar = iconv_open( mb_charset_wchar.c_str(), codepage ); |
@@ -309,19 +292,19 @@ | ||
309 | 292 | #else // MB_USE_ICONV |
310 | 293 | fp->descripter_for_wchar = MB_INVALID; |
311 | 294 | if( strcmp( codepage, "UTF-8" ) == 0 || |
312 | - strcmp( codepage, "UTF8" ) == 0 ){ | |
295 | + strcmp( codepage, "UTF8" ) == 0 ){ | |
313 | 296 | fp->descripter_for_wchar = CP_UTF8; |
314 | 297 | }else if( strcmp( codepage, "UTF-7" ) == 0 || |
315 | - strcmp( codepage, "UTF7" ) == 0 ){ | |
298 | + strcmp( codepage, "UTF7" ) == 0 ){ | |
316 | 299 | fp->descripter_for_wchar = CP_UTF7; |
317 | 300 | }else if( strcmp( codepage, "SJIS" ) == 0 || |
318 | - strcmp( codepage, "Shift_JIS" ) == 0 ){ | |
301 | + strcmp( codepage, "Shift_JIS" ) == 0 ){ | |
319 | 302 | fp->descripter_for_wchar = 932; |
320 | 303 | }else if( strcmp( codepage, "JIS" ) == 0 || |
321 | - strcmp( codepage, "ISO-2022-JP" ) == 0 ){ | |
304 | + strcmp( codepage, "ISO-2022-JP" ) == 0 ){ | |
322 | 305 | fp->descripter_for_wchar = 50220; |
323 | 306 | }else if( strcmp( codepage, "UTF-16" ) == 0 || |
324 | - strcmp( codepage, "UTF16" ) == 0 ){ | |
307 | + strcmp( codepage, "UTF16" ) == 0 ){ | |
325 | 308 | fp->descripter_for_wchar = 1200; |
326 | 309 | }else{ |
327 | 310 | fp->descripter_for_wchar = CP_ACP; |
@@ -331,7 +314,50 @@ | ||
331 | 314 | } |
332 | 315 | fp->descripter_for_char = fp->descripter_for_wchar; |
333 | 316 | #endif // MB_USE_ICONV |
317 | +} | |
334 | 318 | |
319 | +/// <summary> | |
320 | +/// 指定したコードページを使って,ソケットを読み込む | |
321 | +/// </summary> | |
322 | +MB_FILE *mb_fopen( int socket, const char *codepage ) | |
323 | +{ | |
324 | + mb_init(); | |
325 | + MB_FILE *fp = (MB_FILE *)malloc( sizeof( MB_FILE ) ); | |
326 | + fp->file = 0; | |
327 | + fp->socket = socket; | |
328 | + | |
329 | + mb_init_descriptor( fp, codepage ); | |
330 | +} | |
331 | + | |
332 | +/** | |
333 | + * 指定したコードページを使って、読込み専用のテキストファイルを開く。 | |
334 | + * MB_FILEから1行ずつ読み込むのは多重定義されたmb_fgetsを使うが、 | |
335 | + * mb_fgets( wstring &line, MB_FILE *fp )のほうは指定したコードページで、 | |
336 | + * mb_fgets( string &line, MB_FILE *fp )のほうはコードページを無視して読み込む。 | |
337 | + * | |
338 | + * @param file_name ファイルの名前 | |
339 | + * @param codepage コードページ | |
340 | + * @returns ファイル記述子 | |
341 | + */ | |
342 | +MB_FILE *mb_fopen( const char *file_name, const char *codepage ){ | |
343 | + mb_init(); | |
344 | + MB_FILE *fp = (MB_FILE *)malloc( sizeof( MB_FILE ) ); | |
345 | + fp->socket = 0; | |
346 | +#ifdef __GNUC__ | |
347 | + fp->file = fopen( file_name, "rb" ); | |
348 | +#else | |
349 | + fopen_s( &(fp->file), file_name, "rb" ); | |
350 | +#endif | |
351 | + if( !(fp->file) ){ | |
352 | +#ifdef _DEBUG | |
353 | + cout << "::mb_fopen; fopen failed; file_name=" << file_name << endl; | |
354 | +#endif | |
355 | + free( fp ); | |
356 | + return NULL; | |
357 | + } | |
358 | + | |
359 | + mb_init_descriptor( fp, codepage ); | |
360 | + | |
335 | 361 | // BOMがある場合は読み飛ばす |
336 | 362 | unsigned int codepage_number = mb_codepage_from_charset_name( codepage ); |
337 | 363 | if( codepage_number == 1208 || codepage_number == 1209 ){ |
@@ -412,6 +438,12 @@ | ||
412 | 438 | if( fp->file ){ |
413 | 439 | ret = fclose( fp->file ); |
414 | 440 | } |
441 | + | |
442 | + if( fp->charbuf ) | |
443 | + { | |
444 | + free( fp->charbuf ); | |
445 | + } | |
446 | + | |
415 | 447 | free( fp ); |
416 | 448 | return ret; |
417 | 449 | } |
@@ -513,40 +545,77 @@ | ||
513 | 545 | return mb_code_check( buf, len, 0x0A ); |
514 | 546 | } |
515 | 547 | |
548 | +void mb_push_charbuf( MB_FILE *file, char *chars ) | |
549 | +{ | |
550 | + for( int i = 0; i < file->unit_len; i++ ) | |
551 | + { | |
552 | + // やばい | |
553 | + file->charbuf[i] = chars[i]; | |
554 | + } | |
555 | +} | |
556 | + | |
516 | 557 | /** |
517 | 558 | * ファイルから指定されたバイト数を読み込みます。 |
518 | 559 | * 読込の途中でEOFになった場合true、それ以外はfalseを返します |
519 | 560 | */ |
520 | -int mb_fread( char *buf, int len, FILE *fp ){ | |
561 | +int mb_fread( char *buf, int len, MB_FILE *src ){ | |
521 | 562 | int ret = 0; |
563 | + | |
564 | + if( src->file ) | |
565 | + { | |
566 | + FILE *fp = src->file; | |
522 | 567 | #ifdef _DEBUG |
523 | - //cout << "::mb_fread; len=" << len << ";\""; | |
568 | + //cout << "::mb_fread; len=" << len << ";\""; | |
524 | 569 | #endif |
525 | - memset( buf, 0, len * sizeof( char ) ); | |
526 | - for( int i = 0; i < len; i++ ){ | |
527 | - int c = fgetc( fp ); | |
528 | - if( c == EOF ){ | |
529 | - return ret; | |
570 | + memset( buf, 0, len * sizeof( char ) ); | |
571 | + int i = 0; | |
572 | + if( src->charbuf[0] != EOF ) | |
573 | + { | |
574 | + for( ;i < src->unit_len; i++ ) | |
575 | + { | |
576 | + buf[i] = src->charbuf[i]; | |
577 | + src->charbuf[i] = EOF; | |
578 | + } | |
579 | + i = src->unit_len; | |
530 | 580 | } |
531 | - buf[i] = (char)c; | |
532 | - ret++; | |
581 | + for( ; i < len; i++ ){ | |
582 | + int c = fgetc( fp ); | |
583 | + if( c == EOF ){ | |
584 | + return ret; | |
585 | + } | |
586 | + buf[i] = (char)c; | |
587 | + ret++; | |
533 | 588 | #ifdef _DEBUG |
534 | - //cout << "c=" << c << ";"; | |
535 | - //char pch[2]; | |
536 | - //pch[0] = (char)c; | |
537 | - //pch[1] = 0; | |
538 | - //string s( pch ); | |
539 | - //cout << s; | |
589 | + //cout << "c=" << c << ";"; | |
590 | + //char pch[2]; | |
591 | + //pch[0] = (char)c; | |
592 | + //pch[1] = 0; | |
593 | + //string s( pch ); | |
594 | + //cout << s; | |
540 | 595 | #endif |
541 | - } | |
596 | + } | |
542 | 597 | #ifdef _DEBUG |
543 | - //cout << "\"" << endl; | |
598 | + //cout << "\"" << endl; | |
544 | 599 | #endif |
600 | + } | |
601 | + else if( src->socket ) | |
602 | + { | |
603 | + int socket = src->socket; | |
604 | + int read_length = read( socket, buf, len ); | |
605 | + if( read_length < len ) | |
606 | + { | |
607 | + ret = 1; | |
608 | + } | |
609 | + else | |
610 | + { | |
611 | + ret = 0; | |
612 | + } | |
613 | + } | |
545 | 614 | return ret; |
546 | 615 | } |
547 | 616 | |
548 | 617 | bool mb_fgets_core( char *buf, int buflen, MB_FILE *file ){ |
549 | - FILE *fp = file->file; | |
618 | + //FILE *fp = file->file; | |
550 | 619 | int unit_buflen = file->unit_len; |
551 | 620 | int unit_bufbytes = sizeof( char ) * unit_buflen; |
552 | 621 | char *unit_buf = (char *)malloc( unit_bufbytes ); |
@@ -560,7 +629,7 @@ | ||
560 | 629 | int j; |
561 | 630 | |
562 | 631 | // 1文字分読み込む |
563 | - int len = mb_fread( unit_buf, unit_buflen, fp ); | |
632 | + int len = mb_fread( unit_buf, unit_buflen, file ); | |
564 | 633 | |
565 | 634 | if( len != unit_buflen ){ |
566 | 635 | // EOFまで読んだ場合 |
@@ -579,13 +648,14 @@ | ||
579 | 648 | }else if( mb_is_cr( unit_buf, unit_buflen ) ){ |
580 | 649 | // 読んだのがCRだった場合 |
581 | 650 | // 次の文字がLFかどうかを調べる |
582 | - len = mb_fread( unit_buf, unit_buflen, fp ); | |
651 | + len = mb_fread( unit_buf, unit_buflen, file ); | |
583 | 652 | if( len == unit_buflen ){ |
584 | 653 | if( mb_is_lf( unit_buf, unit_buflen ) ){ |
585 | 654 | // LFのようだ |
586 | 655 | }else{ |
587 | 656 | // LFでないので、ファイルポインタを戻す |
588 | - fseek( fp, -unit_bufbytes, SEEK_CUR ); | |
657 | + mb_push_charbuf( file, unit_buf ); | |
658 | + //fseek( fp, -unit_bufbytes, SEEK_CUR ); | |
589 | 659 | } |
590 | 660 | } |
591 | 661 | break; |
@@ -592,7 +662,7 @@ | ||
592 | 662 | }else if( mb_is_lf( unit_buf, unit_buflen ) ){ |
593 | 663 | // 読んだのがLFだった場合 |
594 | 664 | // 次の文字がCRかどうかを調べる |
595 | - len = mb_fread( unit_buf, unit_buflen, fp ); | |
665 | + len = mb_fread( unit_buf, unit_buflen, file ); | |
596 | 666 | if( len == unit_buflen ){ |
597 | 667 | if( mb_is_cr( unit_buf, unit_buflen ) ){ |
598 | 668 | // CRのようだ |
@@ -599,7 +669,8 @@ | ||
599 | 669 | // LF-CRという改行方法があるかどうかは知らないけれどサポートしとこう |
600 | 670 | }else{ |
601 | 671 | // CRでないので、ファイルポインタを戻す |
602 | - fseek( fp, -unit_bufbytes, SEEK_CUR ); | |
672 | + mb_push_charbuf( file, unit_buf ); | |
673 | + //fseek( fp, -unit_bufbytes, SEEK_CUR ); | |
603 | 674 | } |
604 | 675 | } |
605 | 676 | break; |
@@ -21,7 +21,9 @@ | ||
21 | 21 | { |
22 | 22 | string_t lyric = itr->first; |
23 | 23 | this->getStandData( lyric, options ); |
24 | - cout << "corpusManager::analyze; lyric=" << lyric << endl; | |
24 | + string str_lyric; | |
25 | + mb_conv( lyric, str_lyric ); | |
26 | + cout << "corpusManager::analyze; lyric=" << str_lyric << endl; | |
25 | 27 | } |
26 | 28 | } |
27 | 29 |
@@ -2,11 +2,12 @@ | ||
2 | 2 | ./stand/vConnect.cpp ./stand/vowelTable.cpp \ |
3 | 3 | ./stand/mb_text.cpp ./stand/matching.cpp \ |
4 | 4 | \ |
5 | - ./stand/utauVoiceDB/utauVoiceDataBase.cpp ./stand/utauVoiceDB/utauFreq.cpp \ | |
5 | + ./stand/utauVoiceDB/UtauDB.cpp ./stand/utauVoiceDB/utauFreq.cpp \ | |
6 | 6 | \ |
7 | 7 | ./stand/vsqMetaText/vsqBase.cpp ./stand/vsqMetaText/vsqBPList.cpp \ |
8 | 8 | ./stand/vsqMetaText/vsqEventEx.cpp ./stand/vsqMetaText/vsqEventList.cpp \ |
9 | 9 | ./stand/vsqMetaText/vsqFileEx.cpp ./stand/vsqMetaText/vsqHandle.cpp \ |
10 | + ./stand/vsqMetaText/TextReader.cpp \ | |
10 | 11 | ./stand/vsqMetaText/vsqTempo.cpp \ |
11 | 12 | \ |
12 | 13 | ./stand/waveFileEx/waveFileEx.cpp \ |