Package com.music.model.persistent

Examples of com.music.model.persistent.Piece


    private Map<String, Deque<WebSocketMessage<?>>> messages = new ConcurrentHashMap<>();

    @Before
    public void init() {
        MockitoAnnotations.initMocks(this);
        piece = new Piece();
        piece.setId(1L);
        piece.setTempo(60);
        piece.setMetreNumerator(4);
        piece.setMetreDenominator(8);
        piece.setMainInstrument(1);
View Full Code Here


    }

    @Test
    public void derivedMetreTest() {
        Game game = new Game("1", null);
        Piece piece = new Piece();
        piece.setMetreNumerator(4);
        piece.setMetreDenominator(4);
        Assert.assertFalse(game.isNotDerivedMetre(piece, new int[] {8, 8}));
        Assert.assertTrue(game.isNotDerivedMetre(piece, new int[] {4, 8}));

        piece.setMetreNumerator(8);
        piece.setMetreDenominator(8);
        Assert.assertFalse(game.isNotDerivedMetre(piece, new int[] {4, 4}));
        Assert.assertTrue(game.isNotDerivedMetre(piece, new int[] {2, 4}));

        piece.setMetreNumerator(2);
        piece.setMetreDenominator(4);
        Assert.assertFalse(game.isNotDerivedMetre(piece, new int[] {4, 8}));
        Assert.assertFalse(game.isNotDerivedMetre(piece, new int[] {2, 4}));
        Assert.assertTrue(game.isNotDerivedMetre(piece, new int[] {4, 4}));

    }
View Full Code Here

                prefs.setTempo(Tempo.ANY);
                pieces = pieceDao.getByPreferences(prefs);
            }
        }

        Piece piece = pieces.get(random.nextInt(pieces.size()));
        meta.setPiece(piece);
        return meta;
    }
View Full Code Here

    }

    @RequestMapping("/track/{id}")
    public String getTrack(@PathVariable long id, Model model) {
        model.addAttribute("pieceId", id);
        Piece piece = pieceService.getPiece(id);
        if (piece != null) {
            model.addAttribute("title", piece.getTitle());
            model.addAttribute("likes", piece.getLikes());
            return "track";
        } else {
            logger.warn("No track with id=" + id + " found");
            return "redirect:/";
        }
View Full Code Here

            midi = baos.toByteArray();
            mp3 = generator.toMp3(midi);
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
        Piece piece = savePiece(ctx, mp3, midi);

        return piece.getId();
    }
View Full Code Here

            PieceEvaluation evaluation = new PieceEvaluation();
            evaluation.setDateTime(new DateTime());
            if (userId != null) {
                evaluation.setUser(dao.getById(User.class, userId));
            }
            Piece piece = dao.getById(Piece.class, pieceId);
            evaluation.setPiece(piece);
            evaluation.setPositive(positive);
            evaluation.setIp(ip);
            dao.persist(evaluation);

            // not exact due to race condition - a job should count likes every
            // X minutes
            if (positive) {
                piece.setLikes(piece.getLikes() + 1);
            } else {
                piece.setLikes(piece.getLikes() - 1);
            }
        }
    }
View Full Code Here

            }
        }
    }

    private Piece savePiece(ScoreContext ctx, byte[] mp3, byte[] midi) {
        Piece piece = new Piece();
        piece.setNewlyCreated(true);
        piece.setGenerationTime(new DateTime());
        piece.setTitle(ctx.getScore().getTitle());
        piece.setKeyNote(ctx.getKeyNote());
        piece.setMeasures(ctx.getMeasures());
        piece.setNormalizedMeasureSize(ctx.getNormalizedMeasureSize());
        piece.setTempo((int) ctx.getScore().getTempo());
        piece.setNoteLengthCoefficient(ctx.getNoteLengthCoefficient());
        piece.setScale(ctx.getScale());
        piece.setAlternativeScale(ctx.getAlternativeScale());
        piece.setUpBeatLength(ctx.getUpBeatLength());
        piece.setMetreNumerator(ctx.getMetre()[0]);
        piece.setMetreDenominator(ctx.getMetre()[1]);
        piece.setMainInstrument(ctx.getParts().get(PartType.MAIN).getInstrument());
        piece.setVariation(ctx.getVariation());
        piece.setParts(joiner.join(ctx.getParts().keySet()));
        piece.setAlgorithmVersion(algorithmVersion);

        piece.getIntermediateDecisions().setDullBass(ctx.isDullBass());
        piece.getIntermediateDecisions().setFourToTheFloor(ctx.isFourToTheFloor());
        piece.getIntermediateDecisions().setSimplePhrases(ctx.isSimplePhrases());
        piece.getIntermediateDecisions().setAccompaniment(ctx.getParts().containsKey(PartType.ACCOMPANIMENT));
        piece.getIntermediateDecisions().setDrums(ctx.getParts().containsKey(PartType.PERCUSSIONS));
        piece.getIntermediateDecisions().setClassical(
                ctx.getParts().get(PartType.MAIN).getInstrument() == Instruments.PIANO
                        && piece.getIntermediateDecisions().isAccompaniment());
        piece.getIntermediateDecisions().setTempoType(Tempo.forValue(piece.getTempo()));
        piece.getIntermediateDecisions().setElectronic(ctx.isElectronic());
        piece.getIntermediateDecisions().setDissonant(ctx.isDissonant());
        piece.getIntermediateDecisions().setOrnamented(ctx.isOrnamented());
        piece.getIntermediateDecisions().setVariations(StringUtils.left(joiner.join(ctx.getVariations()), 2000));

        Piece result = dao.persist(piece);

        try {
            fileStorageService.storeFile(getMp3FilePath(result.getId()), mp3);
            fileStorageService.storeFile(getMidiFilePath(result.getId()), midi);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
        return result;
    }
View Full Code Here

        play.setDateTime(new DateTime());
        play.setMobileApp(mobileApp);
        if (userId != null) {
            play.setUser(dao.getById(User.class, userId));
        }
        Piece piece = dao.getById(Piece.class, pieceId);
        play.setPiece(piece);
        play.setIp(ip);
        dao.persist(play);

        if (piece.isNewlyCreated()) {
            // we don't care about isolation here - 2 or more users can get (and
            // set new=false to) the same piece and that's OK
            piece.setNewlyCreated(false);
            dao.persist(piece);
        }
    }
View Full Code Here

            throw new IllegalStateException(ex);
        }
    }

    public InputStream getPieceMusicXml(long id) throws IOException {
        Piece piece = dao.getById(Piece.class, id);
        try (InputStream is = fileStorageService.getFile(getMidiFilePath(id))) {
            ByteArrayOutputStream result = new ByteArrayOutputStream();
            Score score = new Score();
            SMFTools localSMF = new SMFTools();
            localSMF.read(is);
            SMFTools.SMFToScore(score, localSMF);
            score.setTitle(piece.getTitle());
            score.setNumerator(piece.getMetreNumerator());
            score.setDenominator(piece.getMetreDenominator());
            MusicXmlRenderer.render(score, result);
            return new ByteArrayInputStream(result.toByteArray());
        }
    }
View Full Code Here

        return dao.getById(Piece.class, id);
    }

    @Transactional
    public long getNextPieceId(UserPreferences preferences) {
        Piece piece = dao.getNewlyCreatedPiece(preferences);
        long id = 1;
        if (piece == null && preferences.isDefault()) {
            id = getRandomPieceId();
        } else if (piece == null && !preferences.isDefault()) {
            List<Piece> pieces = dao.getByPreferences(preferences);
            if (!pieces.isEmpty()) {
                id = pieces.get(random.nextInt(pieces.size())).getId();
            } else {
                id = getRandomPieceId();
            }
        } else {
            id = piece.getId();
        }
        sharedData.getListeningRequests().incrementAndGet();
        return id;
    }
View Full Code Here

TOP

Related Classes of com.music.model.persistent.Piece

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.