⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graph_widget.cc

📁 一个共享源码的音频库4
💻 CC
📖 第 1 页 / 共 2 页
字号:
// This file contains no license whatsoever. It is provided in the public domain as an example// of how to use the audio library//// Bruce Forsberg// forsberg@tns.net// //#include <iostream.h>#include <stdio.h>#include "graph_widget.h"#include "plot.h"#define MARKER_DELTA  5#define TOP_MARGIN    10#define BOTTOM_MARGIN 20#define ZERO_TIME_STRING "00:00:00.00"graph_widget::graph_widget(   Widget  parent,   Widget  left,   Widget  right,   Widget  top,   Widget  bottom,   int     height,   int     width,   int     channels){   _height   = height;   _width    = width;   _channels = channels;   _init_gc  = FALSE;   _back_buf = 0;   _marker_selected = MARKER_NONE;   _marker_samples_per_second = 0;   _marker_delta = 1;   strcpy(_start_time, ZERO_TIME_STRING);   strcpy(_stop_time, ZERO_TIME_STRING);   strcpy(_begin_time, ZERO_TIME_STRING);   strcpy(_end_time, ZERO_TIME_STRING);   strcpy(_current_time, ZERO_TIME_STRING);   _name_string[0] = 0;   _start_sample = 0;   _stop_sample = 0;   _begin_sample = 0;   _end_sample = 0;   _current_sample = 0;   _begin_marker = 0;   _end_marker = width - 1;   _current_marker = 0;   _data_array = NULL;   _divisor = 1;   _shift_data = 0;   _shift_start_x = 0;   _shift_start_y = 0;   _shift_stop_x = 0;   _shift_stop_y = 0;   _total_samples = 0;   _slider_x = -1;   allocateMemory();   build_widget(parent, left, right, top, bottom);}graph_widget::~graph_widget(){   delete [] _data_array;}voidgraph_widget::allocateMemory(){   delete [] _data_array;   // Allocate memory for data storage   _data_array = new XSegment[_width * _channels];}voidgraph_widget::load_new_data(int *data){   // This function will load new data into the graph. This data must be   // width * channels in length. All of the first channel data should be   // first followed by the second channel data.   int  i, chan, index;   int  h, off;   h = _height / _channels;   for (chan = 0; chan < _channels; chan++)   {      off = h * chan + TOP_MARGIN;      for (i = 0; i < _width; i++)      {         index = i + _width * chan;         _data_array[index].y1 = data[index] / _channels + off;         _data_array[index].x1 = i;         if (data[index] > _height/2)            _data_array[index].y2 = h/2 - (data[index]/_channels - h/2) + off;         else            _data_array[index].y2 = h/2 + (h/2 - data[index]/_channels) + off;         _data_array[index].x2 = i;      }   }}voidgraph_widget::perform_expose(){   // This function will perform an expose of the widget   expose(_w, (caddr_t)this, NULL);}voidgraph_widget::setSamplesPerSecond(long samples){   _marker_samples_per_second = samples;}longgraph_widget::getSamplesPerSecond() const{   return (_marker_samples_per_second);}voidgraph_widget::setMarkerResolution(int res){   _marker_delta = res;}intgraph_widget::getMarkerResolution() const{   return (_marker_delta);}voidgraph_widget::setTotalSamples(long long samples){   _total_samples = samples;}long longgraph_widget::getTotalSamples() const{   return (_total_samples);}voidgraph_widget::setStartSamples(long long samples){   _start_sample = samples;   convertToTimeString(_start_sample, _start_time);   // These are based on _start_sample so we update again.   setBeginSamples(_begin_sample);   setEndSamples(_begin_sample);}long longgraph_widget::getStartSamples() const{   return (_start_sample);}voidgraph_widget::setStopSamples(long long samples){   _stop_sample = samples;   convertToTimeString(_stop_sample, _stop_time);}long longgraph_widget::getStopSamples() const{   return (_stop_sample);}voidgraph_widget::setBeginSamples(long long samples){   _begin_sample = samples;   _begin_marker = _begin_sample / _marker_delta;   convertToTimeString(_begin_sample + _start_sample, _begin_time);}      long longgraph_widget::getBeginSamples() const{   return (_begin_sample);}voidgraph_widget::setEndSamples(long long samples){   _end_sample = samples;   _end_marker = _end_sample / _marker_delta;   convertToTimeString(_end_sample + _start_sample, _end_time);}long longgraph_widget::getEndSamples() const{   return (_end_sample);}voidgraph_widget::setCurrentSamples(long long samples){   _current_sample = samples;   _current_marker = _current_sample / _marker_delta;   convertToTimeString(_current_sample, _current_time);}long longgraph_widget::getCurrentSamples() const{   return (_end_sample);}voidgraph_widget::setChannels(int chan){   _channels = chan;   allocateMemory();}intgraph_widget::getChannels() const{   return (_channels);}voidgraph_widget::setDivisor(int div){   if (div == 0)   {      div = 1;      _shift_data *= 2;   }   _divisor = div;}intgraph_widget::getDivisor() const{   return (_divisor);}voidgraph_widget::setShiftData(int shift_data){   _shift_data = shift_data;   if (_shift_data < 0)      _shift_data = 0;}intgraph_widget::getShiftData() const{  return (_shift_data);}Widgetgraph_widget::getWidget() const{   return (_w);}voidgraph_widget::setName(const char * str){   // This function limits the string length to 256 characters   strncpy(_name_string, str, GRAPH_WIDGET_NAME_STRING);}voidgraph_widget::button_press_callback(   Widget w,   caddr_t client_data,   XEvent    *event,   Boolean   *flag){   int x = event->xbutton.x;   int y = event->xbutton.y;   int d = MARKER_DELTA;   graph_widget * obj = (graph_widget *)client_data;   // IF pointer is at begin marker   if ((obj->_begin_marker > (x-d)) && (obj->_begin_marker < (x+d)))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -