logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

[mb-commits] r7910 - in libmusicbrainz/branches/xmlws: include/musicbrainz3: msg#00134

Subject: [mb-commits] r7910 - in libmusicbrainz/branches/xmlws: include/musicbrainz3 src test
Author: luks
Date: 2006-06-22 22:33:27 +0000 (Thu, 22 Jun 2006)
New Revision: 7910

Added:
   libmusicbrainz/branches/xmlws/test/test_disc.cpp
Modified:
   libmusicbrainz/branches/xmlws/include/musicbrainz3/disc.h
   libmusicbrainz/branches/xmlws/src/SConscript
   libmusicbrainz/branches/xmlws/src/disc.cpp
   libmusicbrainz/branches/xmlws/test/Makefile.am
   libmusicbrainz/branches/xmlws/test/SConscript
   libmusicbrainz/branches/xmlws/test/test_model.cpp
Log:
Disc ID utilities.

Modified: libmusicbrainz/branches/xmlws/include/musicbrainz3/disc.h
===================================================================
--- libmusicbrainz/branches/xmlws/include/musicbrainz3/disc.h   2006-06-22 
21:49:50 UTC (rev 7909)
+++ libmusicbrainz/branches/xmlws/include/musicbrainz3/disc.h   2006-06-22 
22:33:27 UTC (rev 7910)
@@ -30,7 +30,7 @@
 
 namespace MusicBrainz
 {
-       
+
        /**
         * Represents an Audio CD.
         *
@@ -161,6 +161,67 @@
                Disc::TrackList tracks;
        };
        
+       /**
+        * The Audio CD could not be read.
+        *
+        * This may be simply because no disc was in the drive, the device name
+        * was wrong or the disc can't be read. Reading errors can occur in case
+        * of a damaged disc or a copy protection mechanism, for example. 
+        */
+       class MB_API DiscError : public Exception
+       {
+       public:
+               DiscError(const std::string &msg = std::string()) : 
Exception(msg) {}
+       };
+       
+       /**
+        * Reads an Audio CD in the disc drive.
+        *
+        * This reads a CD's table of contents (TOC) and calculates the 
MusicBrainz
+        * DiscID, which is a 28 character ASCII string. This DiscID can be used
+        * to retrieve a list of matching releases from the web service (see
+        * MusicBrainz::Query).
+        *
+        * Note that an Audio CD has to be in drive for this to work. The
+        * \a deviceName argument may be used to set the device. The default
+        * depends on the operating system (on linux, it's \c "/dev/cdrom").
+        * No network connection is needed for this function.
+        *
+        * If the device doesn't exist or there's no valid Audio CD in the 
drive,
+        * a DiscError exception is raised.
+        *
+        * @param deviceName a string containing the CD drive's device name
+        *
+        * @return a pointer to Disc object
+        *
+        * @raise DiscError if there was a problem reading the disc
+        */
+       MB_API Disc *readDisc(const std::string &deviceName = std::string());
+
+       /**
+        * Returns a URL for adding a disc to the MusicBrainz database.
+        *
+        * A fully initialized Disc object is needed, as
+        * returned by readDisc. A disc object returned by the web service
+        * doesn't provide the necessary information.
+        *
+        * Note that the created URL is intended for interactive use and points
+        * to the MusicBrainz disc submission wizard by default. This method
+        * just returns a URL, no network connection is needed. The disc drive
+        * isn't used.
+        *
+        * @param disc a fully initialized Disc object
+        * @param host a string containing a host name
+        * @param port an integer containing a port number
+        * 
+        * @return a string containing the submission URL
+        * 
+        * @see readDisc 
+        */
+       MB_API std::string getSubmissionUrl(Disc *disc,
+               const std::string &host = "mm.musicbrainz.org",
+               int port = 80);
+       
 }
 
 #endif

Modified: libmusicbrainz/branches/xmlws/src/SConscript
===================================================================
--- libmusicbrainz/branches/xmlws/src/SConscript        2006-06-22 21:49:50 UTC 
(rev 7909)
+++ libmusicbrainz/branches/xmlws/src/SConscript        2006-06-22 22:33:27 UTC 
(rev 7910)
@@ -40,7 +40,7 @@
                                  sources,
                                  CPPPATH=cpp_paths,
                                  CPPDEFINES=cpp_defines,
-                                 LIBS=['advapi32', 'neon', 'wsock32'])
+                                 LIBS=['advapi32', 'neon', 'wsock32', 
'discid', 'winmm'])
 
 env.Alias('install', env.Install('$libdir', musicbrainz3))
 env.Alias('install', env.Install('$includedir/musicbrainz3', includes))

Modified: libmusicbrainz/branches/xmlws/src/disc.cpp
===================================================================
--- libmusicbrainz/branches/xmlws/src/disc.cpp  2006-06-22 21:49:50 UTC (rev 
7909)
+++ libmusicbrainz/branches/xmlws/src/disc.cpp  2006-06-22 22:33:27 UTC (rev 
7910)
@@ -21,6 +21,8 @@
  */
  
 #include <musicbrainz3/disc.h>
+#include <discid/discid.h>
+#include "utilspriv.h"
 
 using namespace std;
 using namespace MusicBrainz;
@@ -95,3 +97,53 @@
     tracks.push_back(track);
 }
 
+Disc *
+MusicBrainz::readDisc(const std::string &deviceName)
+{
+       DiscId *discid = discid_new();
+       if (!discid) {
+               throw DiscError("Couldn't create a new DiscId instance.");
+       }
+       
+       if (!discid_read(discid, deviceName.empty() ? NULL : 
deviceName.c_str())) {
+               string msg(discid_get_error_msg(discid));
+               discid_free(discid);
+               throw DiscError(msg);
+       }
+       
+       Disc *disc = new Disc;
+       disc->setId(discid_get_id(discid));
+       disc->setSectors(discid_get_sectors(discid));
+       disc->setFirstTrackNum(discid_get_first_track_num(discid));
+       disc->setLastTrackNum(discid_get_last_track_num(discid));
+       for (int i = disc->getFirstTrackNum(); i <= disc->getLastTrackNum(); 
i++) {
+               disc->addTrack(Disc::Track(discid_get_track_offset(discid, i),
+                                                                  
discid_get_track_length(discid, i)));
+       }
+       
+       discid_free(discid);
+       return disc;
+}
+
+std::string
+MusicBrainz::getSubmissionUrl(Disc *disc, const std::string &host, int port)
+{
+       string netloc;
+       if (port == 80) 
+               netloc = host;
+       else
+               netloc = host + ":" + intToString(port);
+       
+       string toc = intToString(disc->getFirstTrackNum())
+               + "+" + intToString(disc->getLastTrackNum())
+               + "+" + intToString(disc->getSectors());
+               
+       for (Disc::TrackList::const_iterator i = disc->getTracks().begin();
+                       i < disc->getTracks().end(); i++) {
+               toc += "+" + intToString(i->first);
+       }
+       
+       return "http://"; + netloc + "/bare/cdlookup.html?id=" + disc->getId()
+               + "&toc=" + toc + "&tracks=" + 
intToString(disc->getLastTrackNum());
+}
+

Modified: libmusicbrainz/branches/xmlws/test/Makefile.am
===================================================================
--- libmusicbrainz/branches/xmlws/test/Makefile.am      2006-06-22 21:49:50 UTC 
(rev 7909)
+++ libmusicbrainz/branches/xmlws/test/Makefile.am      2006-06-22 22:33:27 UTC 
(rev 7910)
@@ -11,7 +11,7 @@
        main.cpp test_first.cpp test_model.cpp test_parser.cpp \
        test_parser_artist.cpp test_parser_release.cpp test_parser_track.cpp \
        test_parser_user.cpp test_utils.cpp test_ws_filters.cpp \
-       test_ws_includes.cpp test_ws.cpp
+       test_ws_includes.cpp test_ws.cpp test_disc.cpp
 
 AM_CPPFLAGS = -I$(top_srcdir)/include @CPPUNIT_CFLAGS@
 

Modified: libmusicbrainz/branches/xmlws/test/SConscript
===================================================================
--- libmusicbrainz/branches/xmlws/test/SConscript       2006-06-22 21:49:50 UTC 
(rev 7909)
+++ libmusicbrainz/branches/xmlws/test/SConscript       2006-06-22 22:33:27 UTC 
(rev 7910)
@@ -17,6 +17,7 @@
     'test_ws_filters.cpp',
     'test_ws_includes.cpp',
     'test_ws.cpp',
+    'test_disc.cpp'
     ]
     
 sources = filter(lambda src: src.endswith('.cpp'), dist_files)

Added: libmusicbrainz/branches/xmlws/test/test_disc.cpp


Property changes on: libmusicbrainz/branches/xmlws/test/test_disc.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: libmusicbrainz/branches/xmlws/test/test_model.cpp
===================================================================
--- libmusicbrainz/branches/xmlws/test/test_model.cpp   2006-06-22 21:49:50 UTC 
(rev 7909)
+++ libmusicbrainz/branches/xmlws/test/test_model.cpp   2006-06-22 22:33:27 UTC 
(rev 7910)
@@ -9,7 +9,6 @@
 class ModelTest : public CppUnit::TestFixture
 {
        CPPUNIT_TEST_SUITE(ModelTest);
-       CPPUNIT_TEST(testDiscProperties);
        CPPUNIT_TEST(testArtistProperties);
        CPPUNIT_TEST(testArtistUniqueName);
        CPPUNIT_TEST(testArtistReleases);
@@ -24,23 +23,6 @@
        
 protected:
 
-       void testDiscProperties()
-       {
-               Disc a("X64QNQ5GVfJUFF9MKTe3AD0wbag-");
-               a.setFirstTrackNum(1);
-               a.setLastTrackNum(12);
-               a.setSectors(260075);
-               a.addTrack(Disc::Track(150, 19912));
-               a.addTrack(Disc::Track(20062, 32335));
-               CPPUNIT_ASSERT_EQUAL(string("X64QNQ5GVfJUFF9MKTe3AD0wbag-"), 
a.getId());
-               CPPUNIT_ASSERT_EQUAL(1, a.getFirstTrackNum());
-               CPPUNIT_ASSERT_EQUAL(12, a.getLastTrackNum());
-               CPPUNIT_ASSERT_EQUAL(260075, a.getSectors());
-               CPPUNIT_ASSERT_EQUAL(2, int(a.getTracks().size()));
-               CPPUNIT_ASSERT_EQUAL(150, a.getTracks()[0].first);
-               CPPUNIT_ASSERT_EQUAL(32335, a.getTracks()[1].second);
-       }
-       
        void testArtistProperties()
        {
                Artist a("86e2e2ad-6d1b-44fd-9463-b6683718a1cc", 
Artist::TYPE_PERSON, "Jean Michel Jarre", "Jarre, Jean Michel");


<Prev in Thread] Current Thread [Next in Thread>