X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Ftrunk%2Fsrc%2Fgtkmm%2Fwidget_sound.cpp;h=3d43731da669103fdf512919c800127eb6324fc9;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=631db4b31d9ea6210e354f50e0cc04263732396c;hpb=ce408de81ca266b1f334ee9bc6c8fb7ba1492ed4;p=synfig.git diff --git a/synfig-studio/trunk/src/gtkmm/widget_sound.cpp b/synfig-studio/trunk/src/gtkmm/widget_sound.cpp index 631db4b..3d43731 100644 --- a/synfig-studio/trunk/src/gtkmm/widget_sound.cpp +++ b/synfig-studio/trunk/src/gtkmm/widget_sound.cpp @@ -2,7 +2,7 @@ /*! \file widget_sound.cpp ** \brief Widget Sound Implementation File ** -** $Id: widget_sound.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $ +** $Id$ ** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley @@ -37,6 +37,8 @@ #include "widget_sound.h" #include "audiocontainer.h" +#include "general.h" + #endif /* === U S I N G =========================================================== */ @@ -56,7 +58,7 @@ using studio::AudioProfile; /* === M E T H O D S ======================================================= */ /* === E N T R Y P O I N T ================================================= */ - + studio::Widget_Sound::Widget_Sound() { } @@ -73,14 +75,14 @@ void studio::Widget_Sound::set_position(double t) float upper = adj_timescale->get_upper(); float lower = adj_timescale->get_lower(); float framesize = upper - lower; - + if(t < lower) { lower -= ceil((lower-t)/framesize)*framesize; upper = lower + framesize; adj_timescale->set_lower(lower); adj_timescale->set_upper(upper); adj_timescale->set_value(t); - adj_timescale->changed(); adj_timescale->value_changed(); + adj_timescale->changed(); adj_timescale->value_changed(); }else if(t > upper) { @@ -112,13 +114,13 @@ bool studio::Widget_Sound::set_profile(etl::handle p) //set the profile audioprof = p; - + if(!audioprof) { clear(); return false; } - + return true; } @@ -137,83 +139,83 @@ void studio::Widget_Sound::draw() on_expose_event(); } -bool studio::Widget_Sound::on_expose_event(GdkEventExpose *heh) -{ - if(!get_window()) return false; +bool studio::Widget_Sound::on_expose_event(GdkEventExpose */*heh*/) +{ + if(!get_window()) return false; //clear the background to dark grey Glib::RefPtr gc = Gdk::GC::create(get_window()); - + if(!gc) return false; { Gdk::Rectangle r(0,0,get_width(),get_height()); get_window()->begin_paint_rect(r); } - Gdk::Color c("#3f3f3f"); + Gdk::Color c("#3f3f3f"); gc->set_rgb_fg_color(c); gc->set_background(c); int w = get_width(); int baseline = get_height()/2; get_window()->draw_rectangle(gc,true,0,0,w,get_height()); - + //set up the color to be blue c.set_rgb_p(0,0.5,1); gc->set_rgb_fg_color(c); - + //draw the base line get_window()->draw_line(gc,0,baseline,w,baseline); - + //redraw all the samples from begin to end, but only if we have samples to draw (or there is no space to draw) - + //synfig::warning("Ok rendered everything, now must render actual sound wave"); - if(!audioprof || !adj_timescale || !w) + if(!audioprof || !adj_timescale || !w) { get_window()->end_paint(); return true; } - + //draw you fool! float framesize = adj_timescale->get_upper() - adj_timescale->get_lower(); if(framesize) { float delta=0,cum=0; - + //position in sample space int begin=0,end=0; int cur=0,maxs=0,mins=0; - + int i=0; //pixel counter - + //etl::clock check; check.reset(); - + float position = adj_timescale->get_value(); float samplerate = audioprof->get_samplerate(); - int posi = 0; - //enforce position inside of frame size + int posi = 0; + //enforce position inside of frame size { float offset = audioprof->get_offset(); - + //clamp begin and end to framesize float beginf = adj_timescale->get_lower(); float endf = adj_timescale->get_upper(); - + posi = round_to_int((position-beginf)*w/framesize); //posi = (int)((position-beginf)*w/framesize); - + //calculate in sample space from seconds begin = round_to_int((beginf - offset)*samplerate); end = round_to_int((endf - offset)*samplerate); //begin = (int)((beginf - offset)*samplerate); //end = (int)((endf - offset)*samplerate); } - + delta = (end - begin)/(float)w; //samples per pixel - - /*synfig::warning("Rendering a framesize of %f secs from [%d,%d) samples to %d samples, took %f sec", + + /*synfig::warning("Rendering a framesize of %f secs from [%d,%d) samples to %d samples, took %f sec", framesize, begin, end, w, check());*/ - + cur = begin; i = 0; cum = 0; for(int i=0;idraw_line(gc,i,baseline+bot,i,baseline+top); } } - + //synfig::warning("Drawing audio line"); c.set_rgb_p(1,0,0); gc->set_rgb_fg_color(c); get_window()->draw_line(gc,posi,0,posi,get_height()); } get_window()->end_paint(); - + return true; } @@ -259,16 +261,16 @@ bool studio::Widget_Sound::on_motion_notify_event(GdkEventMotion* event) { //Can't do this if we don't have a time frame (heheh...) if(!adj_timescale) return false; - + double beg = adj_timescale->get_lower(), end = adj_timescale->get_upper(); - + //find event position in time double t = beg + event->x * (end-beg) / get_width(); //signal that we are scrubbing to this new value... signal_scrub()(t); - - + + // We should be able to just call // Widget_Timeslider::on_motion_notify_event(), // but that seems to cause the program to halt @@ -277,45 +279,45 @@ bool studio::Widget_Sound::on_motion_notify_event(GdkEventMotion* event) //adj_timescale->changed(); //return true; } - + return Widget_Timeslider::on_motion_notify_event(event); } bool studio::Widget_Sound::on_button_press_event(GdkEventButton *event) { //Assume button PRESS - + //if we are starting... using left click if(event->button == 1) { if(!adj_timescale) return false; - + double beg = adj_timescale->get_lower(), end = adj_timescale->get_upper(); - + //find event position in time double t = beg + event->x * (end-beg) / get_width(); //signal the attached scrubbing devices... signal_start_scrubbing()(t); - + return true; } - + return Widget_Timeslider::on_button_press_event(event); } bool studio::Widget_Sound::on_button_release_event(GdkEventButton *event) { //Assume button RELEASE - + //if we are ending... using left click if(event->button == 1) { //signal the scrubbing device... to stop signal_stop_scrubbing()(); - + return true; } - + return Widget_Timeslider::on_button_release_event(event); }