bool PymolWriter::handle_point(PointGeometry *g, Color color, std::string name) { setup(name, OTHER); write_color(get_stream(), color); get_stream() << "SPHERE, " << algebra::commas_io(g->get_geometry()) << ", " << .1 << ",\n"; return true; }
void PymolWriter::do_open() { last_frame_ = get_frame(); lastname_ = placeholder_name; get_stream() << "from pymol.cgo import *\nfrom pymol import cmd\n"; get_stream() << "from pymol.vfont import plain\ndata= {}\n"; get_stream() << "curdata= []\n"; open_type_ = NONE; }
static int avi_write_idx1(avi_Context* AVI, avi_RIFF *riff) { int64_t idx_chunk; int i; char tag[5]; io_Stream *stream; avi_Ientry* ie = 0, *tie; int empty, stream_id = -1; idx_chunk = avi_open_tag(AVI, "idx1"); for (i=0;i<AVI->stream_list_size;i++) { stream = get_stream(AVI->stream_list, i); stream->entry=0; } do { empty = 1; for (i=0;i<AVI->stream_list_size;i++) { stream = get_stream(AVI->stream_list, i); avi_Index* indexes = (avi_Index*) stream->indexes; if (indexes->entry <= stream->entry) continue; tie = avi_get_ientry(indexes, stream->entry); if (empty || tie->pos < ie->pos) { ie = tie; stream_id = i; } empty = 0; } if (!empty) { stream = get_stream(AVI->stream_list, stream_id); avi_stream2fourcc(tag, stream); io_write_4cc(AVI->writer, tag); io_write_wl32(AVI->writer, ie->flags); io_write_wl32(AVI->writer, ie->pos); io_write_wl32(AVI->writer, ie->len); stream->entry++; } } while (!empty); avi_close_tag(AVI, idx_chunk); fprintf(stderr, "AVI: wrote idx1\n"); avi_write_counters(AVI, riff); return 0; }
void PymolWriter::do_close() { cleanup(lastname_); int frame = last_frame_; if (frame == -1) frame = 0; get_stream() << "for k in data.keys():\n cmd.load_cgo(data[k], k, " << frame + 1 << ")\n"; get_stream() << "data= {}\n"; get_stream().flush(); }
static int parse_options(term_t options, p_options *info) { term_t tail = PL_copy_term_ref(options); term_t head = PL_new_term_ref(); term_t arg = PL_new_term_ref(); info->window = MAYBE; while(PL_get_list(tail, head, tail)) { atom_t name; int arity; if ( !PL_get_name_arity(head, &name, &arity) || arity != 1 ) return type_error(head, "option"); _PL_get_arg(1, head, arg); if ( name == ATOM_stdin ) { if ( !get_stream(arg, info, &info->streams[0]) ) return FALSE; } else if ( name == ATOM_stdout ) { if ( !get_stream(arg, info, &info->streams[1]) ) return FALSE; } else if ( name == ATOM_stderr ) { if ( !get_stream(arg, info, &info->streams[2]) ) return FALSE; } else if ( name == ATOM_process ) { info->pid = PL_copy_term_ref(arg); } else if ( name == ATOM_detached ) { if ( !PL_get_bool(arg, &info->detached) ) return type_error(arg, "boolean"); } else if ( name == ATOM_cwd ) { #ifdef __WINDOWS__ if ( !PL_get_wchars(arg, NULL, &info->cwd, CVT_ATOM|CVT_STRING|CVT_EXCEPTION|BUF_MALLOC) ) return FALSE; #else if ( !PL_get_chars(arg, &info->cwd, CVT_ATOM|CVT_STRING|CVT_EXCEPTION|BUF_MALLOC|REP_FN) ) return FALSE; #endif } else if ( name == ATOM_window ) { if ( !PL_get_bool(arg, &info->window) ) return type_error(arg, "boolean"); } else if ( name == ATOM_env ) { if ( !parse_environment(arg, info) ) return FALSE; } else return domain_error(head, "process_option"); } if ( !PL_get_nil(tail) ) return type_error(tail, "list"); return TRUE; }
bool PymolWriter::handle_sphere(SphereGeometry *g, Color color, std::string name) { setup(name, OTHER); write_color(get_stream(), color); get_stream() << "SPHERE, " << algebra::commas_io(g->get_geometry().get_center()) << ", " << g->get_geometry().get_radius() << ",\n"; return true; }
void PymolWriter::cleanup(std::string name, bool close) { if (close) { if (open_type_ != NONE) { get_stream() << "END,\n"; open_type_ = NONE; } if (lastname_ != placeholder_name) get_stream() << "]\n"; } lastname_ = placeholder_name; get_stream() << "k= '" << strip_quotes(name) << "'" << std::endl; get_stream() << "if k in data.keys():\n" << " data[k]= data[k]+curdata\nelse:\n" << " data[k]= curdata\n\n"; }
bool ChimeraWriter::handle_ellipsoid(EllipsoidGeometry *g, Color, std::string name) { cleanup(name, false, false); get_stream() << "try:\n"; algebra::VectorD<4> q = g->get_geometry().get_rotation().get_quaternion(); get_stream() << " chimera.runCommand(\"shape ellipsoid radius " << g->get_geometry().get_radius(0) << "," << g->get_geometry().get_radius(1) << "," << g->get_geometry().get_radius(2) << " qrotation " << q[0] << "," << q[1] << "," << q[2] << "," << q[3] << "\")\n"; get_stream() << "except:\n"; get_stream() << " print \"Need Chimera > 1.4 to draw ellipsoids\"\n"; return true; }
bool PymolWriter::handle_polygon(PolygonGeometry *g, Color color, std::string name) { setup(name, TRIANGLES); if (!open_type_) { get_stream() << "BEGIN, TRIANGLES, "; open_type_ = TRIANGLES; } Ints tris = internal::get_triangles(g); algebra::Vector3Ds normals = internal::get_normals(tris, g->get_geometry()); for (unsigned int i = 0; i < tris.size() / 3; ++i) { write_triangle(tris.begin() + 3 * i, tris.begin() + 3 * i + 3, g->get_geometry(), normals, color, get_stream()); } return true; }
bool PymolWriter::handle_cylinder(CylinderGeometry *g, Color color, std::string name) { setup(name, OTHER); write_color(get_stream(), color); // cleanup(name, false); get_stream() << "CYLINDER,\n" << algebra::commas_io( g->get_geometry().get_segment().get_point(0)) << ",\n" << algebra::commas_io(g->get_geometry().get_segment().get_point( 1)) << ",\n" << g->get_geometry().get_radius() << ",\n"; get_stream() << color.get_red() << ", " << color.get_green() << ", " << color.get_blue() << ",\n"; get_stream() << color.get_red() << ", " << color.get_green() << ", " << color.get_blue() << ",\n"; return true; }
/* Acquire and start duplex streams: * type is either LINE6_STREAM_IMPULSE or LINE6_STREAM_MONITOR */ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type) { struct line6_pcm_stream *pstr; int ret = 0, dir; mutex_lock(&line6pcm->state_mutex); for (dir = 0; dir < 2; dir++) { pstr = get_stream(line6pcm, dir); ret = line6_buffer_acquire(line6pcm, pstr, type); if (ret < 0) goto error; if (!pstr->running) line6_wait_clear_audio_urbs(line6pcm, pstr); } for (dir = 0; dir < 2; dir++) { ret = line6_stream_start(line6pcm, dir, type); if (ret < 0) goto error; } error: mutex_unlock(&line6pcm->state_mutex); if (ret < 0) line6_pcm_release(line6pcm, type); return ret; }
/** * Look for a block by directly contacting a particular peer. * * @param target peer that should have the block * @param query hash to query for the block * @param type desired type for the block * @param proc function to call with result * @param proc_cls closure for 'proc' * @return handle to cancel the operation */ struct GSF_StreamRequest * GSF_stream_query (const struct GNUNET_PeerIdentity *target, const struct GNUNET_HashCode *query, enum GNUNET_BLOCK_Type type, GSF_StreamReplyProcessor proc, void *proc_cls) { struct StreamHandle *sh; struct GSF_StreamRequest *sr; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Preparing to send query for %s via stream to %s\n", GNUNET_h2s (query), GNUNET_i2s (target)); sh = get_stream (target); sr = GNUNET_malloc (sizeof (struct GSF_StreamRequest)); sr->sh = sh; sr->proc = proc; sr->proc_cls = proc_cls; sr->type = type; sr->query = *query; GNUNET_CONTAINER_DLL_insert (sh->pending_head, sh->pending_tail, sr); if (GNUNET_YES == sh->is_ready) transmit_pending (sh); return sr; }
bool ChimeraWriter::handle_sphere(SphereGeometry *g, Color color, std::string name) { cleanup(name, true); write_marker(get_stream(), g->get_geometry().get_center(), color, g->get_geometry().get_radius()); return true; }
bool ChimeraWriter::handle_point(PointGeometry *g, Color color, std::string name) { cleanup(name, true); write_marker(get_stream(), g->get_geometry(), color, 0); return true; }
/* common PCM hw_params callback */ int snd_line6_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params) { int ret; struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream); struct line6_pcm_stream *pstr = get_stream(line6pcm, substream->stream); mutex_lock(&line6pcm->state_mutex); ret = line6_buffer_acquire(line6pcm, pstr, substream->stream, LINE6_STREAM_PCM); if (ret < 0) goto error; ret = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); if (ret < 0) { line6_buffer_release(line6pcm, pstr, LINE6_STREAM_PCM); goto error; } pstr->period = params_period_bytes(hw_params); error: mutex_unlock(&line6pcm->state_mutex); return ret; }
/* * FUNCTION UTL_FILE.GET_LINE(file UTL_TYPE.FILE_TYPE, line int DEFAULT NULL) * RETURNS text; * * Reads one line from file. * * Exceptions: * NO_DATA_FOUND, INVALID_FILEHANDLE, INVALID_OPERATION, READ_ERROR */ Datum utl_file_get_line(PG_FUNCTION_ARGS) { int max_linesize = 0; int encoding = 0; FILE *f; text *result; bool iseof; CHECK_FILE_HANDLE(); f = get_stream(PG_GETARG_INT32(0), &max_linesize, &encoding); /* 'len' overwrites max_linesize, but must be smaller than max_linesize */ if (PG_NARGS() > 1 && !PG_ARGISNULL(1)) { int len = PG_GETARG_INT32(1); CHECK_LINESIZE(len); if (max_linesize > len) max_linesize = len; } result = get_line(f, max_linesize, encoding, &iseof); if (iseof) ereport(ERROR, (errcode(ERRCODE_NO_DATA_FOUND), errmsg("no data found"))); PG_RETURN_TEXT_P(result); }
/* Acquire and optionally start duplex streams: * type is either LINE6_STREAM_IMPULSE or LINE6_STREAM_MONITOR */ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int type, bool start) { struct line6_pcm_stream *pstr; int ret = 0, dir; /* TODO: We should assert SNDRV_PCM_STREAM_PLAYBACK/CAPTURE == 0/1 */ mutex_lock(&line6pcm->state_mutex); for (dir = 0; dir < 2; dir++) { pstr = get_stream(line6pcm, dir); ret = line6_buffer_acquire(line6pcm, pstr, dir, type); if (ret < 0) goto error; if (!pstr->running) line6_wait_clear_audio_urbs(line6pcm, pstr); } if (start) { for (dir = 0; dir < 2; dir++) { ret = line6_stream_start(line6pcm, dir, type); if (ret < 0) goto error; } } error: mutex_unlock(&line6pcm->state_mutex); if (ret < 0) line6_pcm_release(line6pcm, type); return ret; }
/* common PCM pointer callback */ snd_pcm_uframes_t snd_line6_pointer(struct snd_pcm_substream *substream) { struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream); struct line6_pcm_stream *pstr = get_stream(line6pcm, substream->stream); return pstr->pos_done; }
/* * FUNCTION UTL_FILE.PUTF(file UTL_FILE.FILE_TYPE, * format text, * arg1 text, * arg2 text, * arg3 text, * arg4 text, * arg5 text) * RETURNS bool; * * Puts formated data to file. Allows %s like subst symbol. * * Exception: * INVALID_FILEHANDLE, INVALID_OPERATION, WRITE_ERROR */ Datum utl_file_putf(PG_FUNCTION_ARGS) { FILE *f; char *format; int max_linesize = 0; int encoding = 0; int format_length; char *fpt; int cur_par = 0; int cur_len = 0; CHECK_FILE_HANDLE(); f = get_stream(PG_GETARG_INT32(0), &max_linesize, &encoding); NOT_NULL_ARG(1); format = encode_text(encoding, PG_GETARG_TEXT_P(1), &format_length); for (fpt = format; format_length > 0; fpt++, format_length--) { if (format_length == 1) { /* last char */ CHECK_LENGTH(++cur_len); if (fputc(*fpt, f) == EOF) CHECK_ERRNO_PUT(); continue; } /* ansi compatible string */ if (fpt[0] == '\\' && fpt[1] == 'n') { CHECK_LENGTH(++cur_len); if (fputc('\n', f) == EOF) CHECK_ERRNO_PUT(); fpt++; format_length--; continue; } if (fpt[0] == '%') { if (fpt[1] == '%') { CHECK_LENGTH(++cur_len); if (fputc('%', f) == EOF) CHECK_ERRNO_PUT(); } else if (fpt[1] == 's' && ++cur_par <= 5 && !PG_ARGISNULL(cur_par + 1)) { cur_len += do_write(fcinfo, cur_par + 1, f, max_linesize - cur_len, encoding); } fpt++; format_length--; continue; } CHECK_LENGTH(++cur_len); if (fputc(fpt[0], f) == EOF) CHECK_ERRNO_PUT(); } PG_RETURN_BOOL(true); }
static inline int64_t rescale_ts(struct ffmpeg_mux *ffm, int64_t val, int idx) { AVStream *stream = get_stream(ffm, idx); return av_rescale_q_rnd(val / stream->codec->time_base.num, stream->codec->time_base, stream->time_base, AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX); }
bool PymolWriter::handle_segment(SegmentGeometry *g, Color color, std::string name) { setup(name, LINES); /*double r= .01*(g->get_geometry().get_point(0)- g->get_geometry() .get_point(1)).get_magnitude();*/ if (!open_type_) { get_stream() << "BEGIN, LINES,\n"; open_type_ = LINES; } write_color(get_stream(), color); get_stream() << "VERTEX, " << algebra::commas_io(g->get_geometry().get_point(0)) << ",\n" << "VERTEX, " << algebra::commas_io(g->get_geometry().get_point(1)) << ",\n"; //<< "END,\n"; return true; }
tm_obj stream_close(tm_obj params){ tm_obj fp_ = get_arg( params, 0, TM_STREAM); FILE* fp = get_stream(fp_); if( fp == NULL ){ tm_raise("stream_close: file is not open"); } fclose(fp); return obj_none; }
void gdsql_log_shutdown(void) { FILE* fp = get_stream(); if (fp != 0 && fp != stderr) fclose(fp); log_name[0] = '\0'; }
bool PymolWriter::handle_surface(SurfaceMeshGeometry *g, Color color, std::string name) { setup(name, TRIANGLES); if (!open_type_) { get_stream() << "BEGIN, TRIANGLES, "; open_type_ = TRIANGLES; } Ints triangles = internal::get_triangles(g); algebra::Vector3Ds normals = internal::get_normals(triangles, g->get_vertexes()); IMP_INTERNAL_CHECK(triangles.size() % 3 == 0, "The returned triangles aren't triangles"); for (unsigned int i = 0; i < triangles.size() / 3; ++i) { write_triangle(triangles.begin() + 3 * i, triangles.begin() + 3 * i + 3, g->get_vertexes(), normals, color, get_stream()); } return true; }
void ChimeraWriter::cleanup(std::string name, bool need_ms, bool need_surf) { if (need_surf) { get_stream() << "if \"" << name << "\" not in surf_sets:\n"; get_stream() << " m=_surface.SurfaceModel()\n"; get_stream() << " m.name= \"" << name << "\"\n"; get_stream() << " surf_sets[\"" << name << "\"]=m\n"; get_stream() << "m= surf_sets[\"" << name << "\"]\n"; } if (need_ms) { get_stream() << "if \"" << name << "\" not in marker_sets:\n"; get_stream() << " s=new_marker_set('" << name << "')\n"; get_stream() << " marker_sets[\"" << name << "\"]=s\n"; get_stream() << "s= marker_sets[\"" << name << "\"]\n"; } }
bool PymolWriter::handle_triangle(TriangleGeometry *g, Color color, std::string name) { setup(name, TRIANGLES); if (!open_type_) { get_stream() << "BEGIN, TRIANGLES, "; open_type_ = TRIANGLES; } Ints tri(3); tri[0] = 0; tri[1] = 1; tri[2] = 2; algebra::Vector3Ds verts(3); verts[0] = g->get_geometry().get_point(0); verts[1] = g->get_geometry().get_point(1); verts[2] = g->get_geometry().get_point(2); algebra::Vector3Ds normals = internal::get_normals(tri, verts); write_triangle(tri.begin(), tri.end(), verts, normals, color, get_stream()); return true; }
void Logger::init(std::ostream* out, Timing::Timer* timer) { // log all messages unless application won't change it set_global_message_level(trivial); // names for message levels m_lvl_names[trivial] = "Trivial:"; m_lvl_names[minor] = "Minor: "; m_lvl_names[major] = "Major: "; m_lvl_names[critical] = "Critical:"; static Timing::No_timer dummy; m_timer = &dummy; // init output stream if (out) { m_out = out; print_heading(*m_out); get_stream(0, major) << "Logger output stream set to " << typeid(*out).name() << ", object is " << m_out; } else { // fallback m_out = &std::clog; print_heading(*m_out); get_stream(0, major) << "Logger output stream set to std::clog"; } // init timer if (timer) { m_timer = timer; get_stream(0, major) << "Logger timer set to " << typeid(*timer).name() << ", object is " << m_timer; } else { // fallback: using No_timer get_stream(0, critical) << "!!! No timer provided; use " << typeid(*m_timer).name() << " as fallback !!!"; get_stream(0, critical) << "!!! Messages would not be timestamped !!!"; } }
/* common PCM hw_free callback */ int snd_line6_hw_free(struct snd_pcm_substream *substream) { struct snd_line6_pcm *line6pcm = snd_pcm_substream_chip(substream); struct line6_pcm_stream *pstr = get_stream(line6pcm, substream->stream); mutex_lock(&line6pcm->state_mutex); line6_buffer_release(line6pcm, pstr, LINE6_STREAM_PCM); mutex_unlock(&line6pcm->state_mutex); return snd_pcm_lib_free_pages(substream); }
void PymolWriter::setup(std::string name, Type type, bool opendata) { if (name == lastname_) { if (open_type_ != type && open_type_ != NONE) { get_stream() << "END,\n"; open_type_ = NONE; } return; } else if (lastname_ != placeholder_name) { cleanup(lastname_); } if (name.empty()) { name = "unnamed"; } get_stream() << "k= '" << strip_quotes(name) << "'\n"; get_stream() << "if not k in data.keys():\n" << " data[k]=[]\n"; if (opendata) get_stream() << "curdata=[\n"; lastname_ = name; }
static int rtsp_stream_change(interfaceMenu_t *pMenu, void* pArg) { int which = CHANNEL_INFO_GET_SCREEN(pArg); unsigned int streamNumber = CHANNEL_INFO_GET_CHANNEL(pArg); dprintf("%s(%d): in %d\n", __FUNCTION__, which, streamNumber); interface_removeEvent(rtsp_stream_start, pArg); if ( appControlInfo.rtspInfo.active != 0 ) { eprintf("RTSP: stop video at %d\n", which); // force showState to NOT be triggered interfacePlayControl.activeButton = interfacePlayControlStop; rtsp_stopVideo(which); } if (streamNumber != CHANNEL_CUSTOM) { interface_setSelectedItem(_M &rtspStreamMenu, streamNumber); if ( pstream_head == NULL ) { int ret = get_rtsp_streams(ppstream_head); dprintf("%s: Found streams %i\n", __FUNCTION__,ret); if (ret != 0 || pstream_head == NULL) { interface_showMessageBox(_T("ERR_DEFAULT_STREAM"), thumbnail_warning, 0); eprintf("RTSP: Failed to find default stream\n"); return -1; } } streams_struct* stream_ptr = get_stream(streamNumber); if ( !stream_ptr ) { interface_showMessageBox(_T("ERR_STREAM_IN_LIST"), thumbnail_error, 0); eprintf("RTSP: Stream number %d not found in linked list\n", streamNumber); return -1; } //dprintf("%s: stream_ptr->stream %s\n", __FUNCTION__, stream_ptr->stream); stream_info.port = appControlInfo.rtspInfo.RTSPPort; strcpy(stream_info.ip, appControlInfo.rtspInfo.streamIP); strcpy(stream_info.streamname, stream_ptr->stream); appControlInfo.playbackInfo.playlistMode = playlistModeNone; stream_info.custom_url = 0; } if ( rtsp_stream_start(pArg) == 0 ) { interface_showMenu(0, 1); return 0; } return -1; }