int main(void) { while (TRUE) { printf("\nTemperature Plotting Program Menu\n"); printf("\tE - Enter temperatures for scratchpad\n"); printf("\tS - Store scratchpad to disk\n"); printf("\tR - Read disk file to scratchpad\n"); printf("\tT - Table view of current data\n"); printf("\tG - Graph view of current data\n"); printf("\tX - Exit the program\n"); printf("\nPress one of the above keys: "); switch (toupper(getche())) { case 'E': get_temps(); break; case 'S': save_temps(); break; case 'R': read_temps(); break; case 'T': table_view(); break; case 'G': graph_view(); break; case 'X': exit(0); } } }
int GraphicCanvas::button_release_event() { if(state == GraphicCanvas::DRAG_POINT && plugin->active_point >= 0) { // Delete point if out of order int point_number = plugin->active_point; GraphicPoint *active_point = temp_points.get(point_number); for(int i = 0; i < temp_points.size(); i++) { GraphicPoint *point = temp_points.get(i); if((point->freq <= active_point->freq && i > point_number) || (point->freq >= active_point->freq && i < point_number)) { temp_points.remove_object_number(point_number); plugin->active_point = -1; process(0, 0, 1); break; } } save_temps(); plugin->send_configure_change(); } state = GraphicCanvas::NONE; return 0; }
void rgb_temp_update(unsigned char *temps) { if (is_same_temp(temps)) return; save_temps(temps); show_saved(); }
void GraphicCanvas::process(int buttonpress, int motion, int draw) { int got_button = 0; int center_y = get_h() / 2; int out_of_order = 0; ArrayList<GraphicPoint*> *points; double *envelope; const int debug = 0; if(state == GraphicCanvas::NONE) { points = &plugin->config.points; envelope = plugin->envelope; } else { points = &temp_points; envelope = temp_envelope; } plugin->calculate_envelope(points, envelope); // spectrogram if(draw) { clear_box(0, 0, get_w(), get_h()); int niquist = plugin->PluginAClient::project_sample_rate / 2; int total_frames = plugin->get_gui_update_frames(); GraphicGUIFrame *frame = (GraphicGUIFrame*)plugin->get_gui_frame(); if(frame) { delete plugin->last_frame; plugin->last_frame = frame; } else { frame = plugin->last_frame; } // Draw most recent frame if(frame) { set_color(MEGREY); int y1 = 0; int y2 = 0; for(int i = 0; i < get_w(); i++) { int freq = Freq::tofreq(i * TOTALFREQS / get_w()); int index = (int64_t)freq * (int64_t)frame->window_size / 2 / niquist; if(index < frame->window_size / 2) { double magnitude = frame->data[index] / frame->freq_max * frame->time_max; y2 = (int)(get_h() - (DB::todb(magnitude) - INFINITYGAIN) * get_h() / -INFINITYGAIN); CLAMP(y2, 0, get_h() - 1); if(i > 0) { draw_line(i - 1, y1, i, y2); //printf(" %.0f", frame->data[index]); } y1 = y2; } } //printf( "\n"); total_frames--; } // Delete remaining frames while(total_frames > 0) { PluginClientFrame *frame = plugin->get_gui_frame(); if(frame) delete frame; total_frames--; } } // Determine if active point is out of order if(plugin->active_point_exists()) { GraphicPoint *active_point = points->get(plugin->active_point); for(int i = 0; i < points->size(); i++) { if(i == plugin->active_point) { if(i < points->size() - 1 && active_point->freq >= points->get(i + 1)->freq || i > 0 && active_point->freq <= points->get(i - 1)->freq) { out_of_order = 1; } break; } } } if(motion) { if(state == GraphicCanvas::DRAG_POINT) { int point_x = get_cursor_x() + x_diff; int point_y = get_cursor_y() + y_diff; CLAMP(point_x, 0, get_w()); CLAMP(point_y, 0, get_h()); int frequency = Freq::tofreq(point_x * TOTALFREQS / get_w()); double magnitude_db = (double)(center_y - point_y) * MAXMAGNITUDE / center_y; int minfreq = Freq::tofreq(0); int maxfreq = Freq::tofreq(TOTALFREQS - 1); CLAMP(frequency, minfreq, maxfreq); CLAMP(magnitude_db, -MAXMAGNITUDE, MAXMAGNITUDE); if(plugin->active_point >= 0) { GraphicPoint *active_point = points->get(plugin->active_point); active_point->freq = frequency; active_point->value = magnitude_db; } // Redraw with new value process(0, 0, 1); save_temps(); plugin->send_configure_change(); gui->update_textboxes(); return; } } // Magnitude bars if(draw) { set_color(GREEN); set_line_dashes(1); for(int i = 1; i < MAJOR_DIVISIONS; i++) { int y = i * get_h() / (MAJOR_DIVISIONS - 1); draw_line(0, y, get_w(), y); } set_line_dashes(0); } int y1 = 0; if(draw) set_color(WHITE); // Control points, cursor change and control point selection int new_cursor = CROSS_CURSOR; for(int i = 0; i < points->size(); i++) { GraphicPoint *point = points->get(i); int x = Freq::fromfreq(point->freq) * get_w() / TOTALFREQS; int y = freq_to_y(point->freq, points, envelope); if(draw) { y1 = y; // Draw point under cursor if out of order if(i == plugin->active_point && out_of_order) y1 = get_cursor_y() + y_diff; if(i == plugin->active_point) draw_box(x - BOX_SIZE / 2, y1 - BOX_SIZE / 2, BOX_SIZE, BOX_SIZE); else draw_rectangle(x - BOX_SIZE / 2, y1 - BOX_SIZE / 2, BOX_SIZE, BOX_SIZE); } if(motion && state == GraphicCanvas::NONE && is_event_win() && cursor_inside()) { if(get_cursor_x() >= x - BOX_SIZE / 2 && get_cursor_y() >= y - BOX_SIZE / 2 && get_cursor_x() < x + BOX_SIZE / 2 && get_cursor_y() < y + BOX_SIZE / 2) { new_cursor = UPRIGHT_ARROW_CURSOR; } } if(buttonpress && state == GraphicCanvas::NONE && is_event_win() && cursor_inside() && !got_button) { if(get_cursor_x() >= x - BOX_SIZE / 2 && get_cursor_y() >= y - BOX_SIZE / 2 && get_cursor_x() < x + BOX_SIZE / 2 && get_cursor_y() < y + BOX_SIZE / 2) { plugin->active_point = i; state = GraphicCanvas::DRAG_POINT; new_temps(); points = &temp_points; envelope = temp_envelope; x_diff = x - get_cursor_x(); y_diff = y - get_cursor_y(); got_button = 1; process(0, 0, 1); save_temps(); plugin->send_configure_change(); gui->update_textboxes(); } } } if(motion && new_cursor != get_cursor()) { set_cursor(new_cursor, 0, 1); } // Envelope line; y1 = 0; set_line_width(2); for(int i = 0; i < get_w(); i++) { int y = freq_to_y(Freq::tofreq(i * TOTALFREQS / get_w()), points, envelope); if(draw) { if(i > 0) draw_line(i - 1, y1, i, y); } y1 = y; } set_line_width(1); if(buttonpress && !got_button) { if(is_event_win() && cursor_inside()) { GraphicPoint *new_point = new GraphicPoint; new_point->freq = Freq::tofreq(get_cursor_x() * TOTALFREQS / get_w()); new_point->value = (double)(center_y - get_cursor_y()) * MAXMAGNITUDE / center_y; state = GraphicCanvas::DRAG_POINT; new_temps(); points = &temp_points; envelope = temp_envelope; insert_point(new_point); plugin->active_point = points->number_of(new_point); x_diff = 0; y_diff = 0; // Redraw with new point process(0, 0, 1); save_temps(); plugin->send_configure_change(); gui->update_textboxes(); } } if(draw) { flash(); } }