And back again.
git-svn-id: svn://localhost/trunk/ardour2@182 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
b3c2be22fe
commit
9f91aca762
@ -23,11 +23,14 @@
|
||||
#include <gtkmm/stock.h>
|
||||
|
||||
#include <ardour/audio_library.h>
|
||||
#include <ardour/sndfile_helpers.h>
|
||||
|
||||
#include "sfdb_ui.h"
|
||||
|
||||
#include "i18n.h"
|
||||
|
||||
std::string length2string (const int32_t frames, const int32_t sample_rate);
|
||||
|
||||
SoundFileBox::SoundFileBox (ARDOUR::Session* session)
|
||||
:
|
||||
current_pid(0),
|
||||
@ -97,7 +100,45 @@ SoundFileBox::SoundFileBox (ARDOUR::Session* session)
|
||||
|
||||
int
|
||||
SoundFileBox::setup_labels (string filename)
|
||||
{return 0;}
|
||||
{
|
||||
SNDFILE *sf;
|
||||
|
||||
if ((sf = sf_open ((char *) filename.c_str(), SFM_READ, &sf_info)) < 0) {
|
||||
error << string_compose(_("file \"%1\" could not be opened"), filename) << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (sf_info.frames == 0 && sf_info.channels == 0 &&
|
||||
sf_info.samplerate == 0 && sf_info.format == 0 &&
|
||||
sf_info.sections == 0) {
|
||||
/* .. ok, its not a sound file */
|
||||
error << string_compose(_("file \"%1\" appears not to be an audio file"), filename) << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
label.set_alignment (0.0f, 0.0f);
|
||||
label.set_text ("Label: " + ARDOUR::Library->get_label(filename));
|
||||
|
||||
path.set_text ("Path: ");
|
||||
path_entry.set_text (filename);
|
||||
path_entry.set_position (-1);
|
||||
|
||||
length.set_alignment (0.0f, 0.0f);
|
||||
length.set_text (string_compose("Length: %1", length2string(sf_info.frames, sf_info.samplerate)));
|
||||
|
||||
format.set_alignment (0.0f, 0.0f);
|
||||
format.set_text (string_compose("Format: %1, %2",
|
||||
sndfile_major_format(sf_info.format),
|
||||
sndfile_minor_format(sf_info.format)));
|
||||
|
||||
channels.set_alignment (0.0f, 0.0f);
|
||||
channels.set_text (string_compose("Channels: %1", sf_info.channels));
|
||||
|
||||
samplerate.set_alignment (0.0f, 0.0f);
|
||||
samplerate.set_text (string_compose("Samplerate: %1", sf_info.samplerate));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
SoundFileBox::setup_fields ()
|
||||
@ -129,7 +170,9 @@ SoundFileBox::field_selected ()
|
||||
|
||||
bool
|
||||
SoundFileBox::update (std::string filename)
|
||||
{return true;}
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
SoundFileBrowser::SoundFileBrowser (std::string title)
|
||||
:
|
||||
@ -192,3 +235,22 @@ SoundFileOmega::import_clicked ()
|
||||
Imported (chooser.get_filenames(), split_check.get_active());
|
||||
}
|
||||
|
||||
std::string
|
||||
length2string (const int32_t frames, const int32_t sample_rate)
|
||||
{
|
||||
int secs = (int) (frames / (float) sample_rate);
|
||||
int hrs = secs / 3600;
|
||||
secs -= (hrs * 3600);
|
||||
int mins = secs / 60;
|
||||
secs -= (mins * 60);
|
||||
|
||||
int total_secs = (hrs * 3600) + (mins * 60) + secs;
|
||||
int frames_remaining = frames - (total_secs * sample_rate);
|
||||
float fractional_secs = (float) frames_remaining / sample_rate;
|
||||
|
||||
char duration_str[32];
|
||||
sprintf (duration_str, "%02d:%02d:%05.2f", hrs, mins, (float) secs + fractional_secs);
|
||||
|
||||
return duration_str;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user