Extract audio and cue sheet from an NRG audio CD image.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.1 KiB

  1. // This file is part of the NRGrip project.
  2. //
  3. // Copyright (c) 2016, 2018 Matteo Cypriani <mcy@lm7.fr>
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //! NRG SINF chunk data structure and associated functions.
  23. use std::fmt;
  24. use std::fs::File;
  25. use ::error::NrgError;
  26. use super::readers::read_u32;
  27. #[derive(Copy, Clone, Debug)]
  28. pub struct NrgSinf {
  29. pub size: u32,
  30. pub nb_tracks: u32,
  31. }
  32. impl NrgSinf {
  33. pub fn new() -> NrgSinf {
  34. NrgSinf {
  35. size: 0,
  36. nb_tracks: 0,
  37. }
  38. }
  39. }
  40. impl fmt::Display for NrgSinf {
  41. fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
  42. write!(f, "Chunk ID: SINF\n\
  43. Chunk description: Session Information\n\
  44. Chunk size: {} Bytes\n\
  45. Number of tracks in the session: {}",
  46. self.size,
  47. self.nb_tracks)
  48. }
  49. }
  50. /// Reads the NRG Session Information chunk (SINF).
  51. pub fn read_nrg_sinf(fd: &mut File) -> Result<NrgSinf, NrgError> {
  52. let mut chunk = NrgSinf::new();
  53. chunk.size = try!(read_u32(fd));
  54. chunk.nb_tracks = try!(read_u32(fd));
  55. Ok(chunk)
  56. }