njh/rotter — pull request #19 by nick-prater (2012-07-01 18:05:24+00:00)
Title: Fix broken FLAC and vorbis output formats (file open mode)

Patch to fallback to write-only mode if opening files as read/write
fails, for formats handled by libsndfile. This fixes FLAC and
vorbis output formats in rotter.

Commit 128d558572c29cbc23a64d558430c3f3b245f2d9 changed the mode for
opening archive files from SFM_WRITE to SFM_RDWR.

This breaks the flac and vorbis output formats:

$ ./src/rotter -f flac -c 1 /tmp
[INFO] Sun Jul 1 15:43:41 2012 JACK client registered as 'rotter'.
[INFO] Sun Jul 1 15:43:41 2012 Opening new archive file for ringbuffer A: /tmp/2012/07/01/15/archive.flac
[ERROR] Sun Jul 1 15:43:41 2012 Failed to open output file: Error : This file format does not support read/write mode.
[ERROR] Sun Jul 1 15:43:41 2012 Failed to open file.
...

Looking at the latest libsndfile-1.0.25, as provided on Ubuntu 12.04
systems, opening FLAC or vorbis files as SFM_RDWR is not supported.
(See libsndfile's flac.c, around line 632, or ogg_vorbis.c around
line 496.)

This patch falls back to write-only, if we cannot open the file as
read/write.

By using a fallback method (rather than hard-coding the current
capabilities of each format) we will automatically benefit if
libsndfile adds read/write capabilities for more formats.

Note that in write-only mode, we cannot append to existing files,
so their contents, if they exist wll be clobbered, but this is the
original behaviour of rotter, so isn't a regression.